Standard Library: Overloads

Global wrapper functions combining similar type-specific functions

Some modules contain functions with the same name as those in other modules. For example, List, Str, and Table each contain a reverse function. Normally this wouldn't be a problem, but it gets tricky when we want to make those functions global; without a module prefix, how does the language know which version of the function to call?

To solve this, the standard library provides overloaded functions: global wrapper functions combining two or more module functions with the same name. The overloaded function will choose which module function to call based on the type of the first argument it receives. For example, the function Overloads.reverse(values) will call List.reverse(list), Str.reverse(string), or Table.reverse(table) based on the type of values

reverse("hello") -- Calls Str.reverse
reverse([1, 2, 3, 4, 5]) -- Calls List.reverse
"olleh"
[5, 4, 3, 2, 1]
  1. drop
  2. dropLast
  3. isEmpty
  4. len
  5. push
  6. remove
  7. reverse
  8. select
  9. sortBy
  10. sortDescBy
  11. take
  12. takeLast

Overloads.drop(values, count)


Overloads.dropLast(values, count)


Overloads.isEmpty(values)


Overloads.len(values)


Overloads.push(values, item)


Overloads.remove(values, elem)


Overloads.reverse(values)


Overloads.select(collection, keys)


Overloads.sortBy(values, ranker)


Overloads.sortDescBy(values, ranker)


Overloads.take(values, count)


Overloads.takeLast(values, count)