Array Funcers

+

Concatenates two arrays.

TypeValue
InputArr<<A Any>...>an array
other (param #1)Arr<<B Any>...>another array
OutputArr<<A Any>|<B Any>...>the concatenation of both arrays

Examples

ProgramTypeValueError
[1, 2, 3] +[4, 5]Arr<Num...>[1, 2, 3, 4, 5]
[] +[4, 5]Arr<Num...>[4, 5]
[1, 2, 3] +[]Arr<Num...>[1, 2, 3]
[] +[]Arr<>[]
["a", "b"] +["c", "d"]Arr<Str...>["a", "b", "c", "d"]
["a", "b"] +[1, 2]Arr<Str|Num...>["a", "b", 1, 2]

all

Checks if all elements are true.

TypeValue
InputArr<Bool...>an array of boolean values
OutputBooltrue iff all elements of the input are true

Examples

ProgramTypeValueError
[] allBooltrue
[true] allBooltrue
[true, true] allBooltrue
[true, false, true] allBoolfalse

drop

Removes the first n elements from the beginning of an array.

TypeValue
InputArr<<A Any>...>an array
n (param #1)Numnumber of elements to remove
OutputArr<<A Any>...>the input with the first n elements removed

Examples

ProgramTypeValueError
[1, 2, 3] drop(-1)Arr<Num...>[1, 2, 3]
[1, 2, 3] drop(0)Arr<Num...>[1, 2, 3]
[1, 2, 3] drop(1)Arr<Num...>[2, 3]
[1, 2, 3] drop(2)Arr<Num...>[3]
[1, 2, 3] drop(3)Arr<Num...>[]
[1, 2, 3] drop(4)Arr<Num...>[]

dropWhile

Removes elements satisfying a predicate from the beginning of an array.

TypeValue
InputArr<<A Any>...>an array
predicate (param #1)for <A Any> Obj<yes: <B Any>, Any>|Obj<no: <C Any>, Any>a predicate to apply to the elements of the input
OutputArr<<A Any>...>The elements from the input, starting with the first one that does not satisfy the predicate.

Examples

ProgramTypeValueError
[{a: 1}, {a: 2}, {b: 3}, {a: 4}] dropWhile(is {a: _})Arr<Obj<b: Num, Void>|Obj<a: Num, Void>...>[{b: 3}, {a: 4}]

each

Applies a function to every element.

TypeValue
InputArr<<A Any>...>an array
f (param #1)for <A Any> <B Any>a function to apply to each element of the input
OutputArr<<B Any>...>a list with the outputs of f applied to each element of the input

Examples

ProgramTypeValueError
[1, 2, 3] each(*2)Arr<Num...>[2, 4, 6]
[{a: 1}, {a: 2}, {b: 3}, {a: 4}] takeWhile(is {a: _}) each(@a)Arr<Num...>[1, 2]

enum

Pairs each element with a 0-based index.

TypeValue
InputArr<<A Any>...>
OutputArr<Arr<Num, <A Any>>...>the input with each element replaced with a 2-element array, the second element of which is the original element and the first is its index in the array, counting from 0

Examples

ProgramTypeValueError
["a", "b", "c"] enumArr<Arr<Num, Str>...>[[0, "a"], [1, "b"], [2, "c"]]

enum

Pairs each element with an index.

TypeValue
InputArr<<A Any>...>an array
start (param #1)Numat which number to start counting
OutputArr<Arr<Num, <A Any>>...>the input with each element replaced with a 2-element array, the second element of which is the original element and the first is its index in the array, counting from start

Examples

ProgramTypeValueError
["a", "b", "c"] enum(1)Arr<Arr<Num, Str>...>[[1, "a"], [2, "b"], [3, "c"]]

findFirst

Finds the index and first element satisfying a predicate.

TypeValue
InputArr<<A Any>...>an array
predicate (param #1)for <A Any> Obj<yes: <B Any>, Any>|Obj<no: <C Any>, Any>a predicate to apply to elements of the input
OutputNull|Arr<Num, <A Any>>the first element of the input satisfying the predicate, paired with its index, or Null if none

Examples

ProgramTypeValueError
[1, 2, 3] findFirst(is Num with %2 ==0)Null|Arr<Num, Num>[1, 2]
[1, 2, 3] findFirst(is Num with %4 ==0)Null|Arr<Num, Num>null

findFirstIndex

Finds the index of the first element satisfying a predicate.

TypeValue
InputArr<<A Any>...>an array
predicate (param #1)for <A Any> Obj<yes: <B Any>, Any>|Obj<no: <C Any>, Any>a predicate to apply to elements of the input
OutputNull|Numthe index of the first element of the input satisfying the predicate, or Null if none

Examples

ProgramTypeValueError
[1, 2, 3] findFirstIndex(is Num with %2 ==0)Null|Num1
[1, 2, 3] findFirstIndex(is Num with %4 ==0)Null|Numnull

findFirstValue

Finds the first element satisfying a predicate.

TypeValue
InputArr<<A Any>...>an array
predicate (param #1)for <A Any> Obj<yes: <B Any>, Any>|Obj<no: <C Any>, Any>a predicate to apply to elements of the input
OutputNull|<A Any>the first element of the input satisfying the predicate, or Null if none

Examples

ProgramTypeValueError
[1, 2, 3] findFirstValue(is Num with %2 ==0)Null|Num2
[1, 2, 3] findFirstValue(is Num with %4 ==0)Null|Numnull

findLast

Finds the index and last element satisfying a predicate.

TypeValue
InputArr<<A Any>...>an array
predicate (param #1)for <A Any> Obj<yes: <B Any>, Any>|Obj<no: <C Any>, Any>a predicate to apply to elements of the input
OutputNull|Arr<Num, <A Any>>the last element of the input satisfying the predicate, paired with its index, or Null if none

Examples

ProgramTypeValueError
[1, 2, 3, 4] findLast(is Num with %2 ==0)Null|Arr<Num, Num>[3, 4]
[1, 2, 3, 4] findLast(is Num with %8 ==0)Null|Arr<Num, Num>null

findLastIndex

Finds the index of the last element satisfying a predicate.

TypeValue
InputArr<<A Any>...>an array
predicate (param #1)for <A Any> Obj<yes: <B Any>, Any>|Obj<no: <C Any>, Any>a predicate to apply to elements of the input
OutputNull|Numthe index of the last element of the input satisfying the predicate, or Null if none

Examples

ProgramTypeValueError
[1, 2, 3, 4] findLastIndex(is Num with %2 ==0)Null|Num3
[1, 2, 3, 4] findLastIndex(is Num with %8 ==0)Null|Numnull

findLastValue

Finds the last element satisfying a predicate.

TypeValue
InputArr<<A Any>...>an array
predicate (param #1)for <A Any> Obj<yes: <B Any>, Any>|Obj<no: <C Any>, Any>a predicate to apply to elements of the input
OutputNull|<A Any>the last element of the input satisfying the predicate, or Null if none

Examples

ProgramTypeValueError
[1, 2, 3, 4] findLastValue(is Num with %2 ==0)Null|Num4
[1, 2, 3, 4] findLastValue(is Num with %8 ==0)Null|Numnull

fold

Aggregates an array recursively.

TypeValue
InputArr<<A Any>...>an array
start (param #1)<B Any>initial accumulator
combine (param #2)for <B Any> (<A Any>) <B Any>a function that combines the current accumulator with the next element to produce a new accumulator
Output<B Any>the accumulator after processing all elements

Examples

ProgramTypeValueError
[2, 3, 4] fold(0, +)Num9
[2, 3, 4] fold(1, *)Num24

get

Returns the element at a given index.

TypeValue
InputArr<<A Any>...>an array
index (param #1)Numa 0-based index into the input
Output<A Any>the element at the given index

Throws BadIndex if the index is invalid or NoSuchIndex if there is not element at the give index.

Examples

ProgramTypeValueError
[] get(0)VoidType error
Code: VoidProgram
Message: Type of program cannot be Void.
["a", "b", "c"] get(0)Str"a"
["a", "b", "c"] get(-1)StrValue error
Code: BadIndex
Message: Index must be a nonnegative integer.
Got value: -1
["a", "b", "c"] get(2)Str"c"
["a", "b", "c"] get(3)StrValue error
Code: NoSuchIndex
Message: Array is not long enough.
Got value: 3

get

Returns the element at a given index, or a default value.

TypeValue
InputArr<<A Any>...>an array
index (param #1)Numa 0-based index into the input
default (param #2)<B Any>default value to retur if there is no element at the given index
Output<A Any>|<B Any>the element at the given index, or default if there isn't one.

Throws BadIndex if the index is invalid.

Examples

ProgramTypeValueError
[] get(0, null)Nullnull
["a", "b", "c"] get(0, null)Str|Null"a"
["a", "b", "c"] get(-1, null)Str|NullValue error
Code: BadIndex
Message: Index must be a nonnegative integer.
Got value: -1
["a", "b", "c"] get(3, null)Str|Nullnull

join

Join several arrays together into one.

TypeValue
InputArr<Arr<<A Any>...>...>an array of arrays
OutputArr<<A Any>...>All arrays in the input joined together into one.

Examples

ProgramTypeValueError
[] joinArr<<A>...>[]
[[]] joinArr<>[]
[[1]] joinArr<Num...>[1]
[[1, 2]] joinArr<Num...>[1, 2]
[[], []] joinArr<>[]
[[], [1]] joinArr<Num...>[1]
[[1], [2, 3]] joinArr<Num...>[1, 2, 3]
[[1], [2, [3]]] joinArr<Num|Arr<Num>...>[1, 2, [3]]

keep

Keep only elements satisfying a predicate.

TypeValue
InputArr<<A Any>...>an array
predicate (param #1)for <A Any> Obj<yes: <B Any>, Any>|Obj<no: <C Any>, Any>a predicate to apply to elements of the input
OutputArr<<B Any>...>The input with all elements not satisfying the predicate removed.

Examples

ProgramTypeValueError
["a", 1, "b", 2, "c", 3] keep(is Num with %2 >0 elis Str)Arr<Num|Str...>["a", 1, "b", "c", 3]
[{n: 1}, {n: 2}, {n: 3}] keep(is {n: n} with n %2 >0)Arr<Obj<n: Num, Void>...>[{n: 1}, {n: 3}]
[1, 2, 3, 4, 5, 6] keep(if %2 ==0) each(*2)Arr<Num...>[4, 8, 12]
[1, 2, 3, 4, 5, 6] keep(if %2 ==0 not) each(id)Arr<Num...>[1, 3, 5]
[1, 2, 3] keep(if %2 ==0 not) each(+1)Arr<Num...>[2, 4]
[1, 2, 3] keep(if false)Arr<Num...>[]
[{n: 1}, 2, {n: 3}] keep(is {n: n}) each(@n)Arr<Num...>[1, 3]

len

Computes the length of an array.

TypeValue
InputArr<Any...>an array
OutputNumhow many elements the input has

Examples

ProgramTypeValueError
[] lenNum0
["a", 2, []] lenNum3

max

Finds the maximum element.

TypeValue
InputArr<<A Any>...>an array
less (param #1)for <A Any> (<A Any>) Boolfuncer that tests whether its input is "less than" its first argument
default (param #2)<B Any>default value to return if the input is empty
Output<A Any>|<B Any>the maximum element, or default if the input is empty

Examples

ProgramTypeValueError
["abc", "b", "ab"] max(<, "")Str"b"
[0, 1, 2] max(>, -100)Num0
for Any def f Arr<Num...> as [] ok f max(<, 0)Num0

max

Finds the maximum element according to a sorting key.

TypeValue
InputArr<<A Any>...>an array
sortKey (param #1)for <A Any> <B Any>funcer that maps input elements to values by which they will be compared
less (param #2)for <B Any> (<B Any>) Boolfuncer that tests whether its input is "less than" its first argument
default (param #3)<C Any>default value to return if the input is empty
Output<A Any>|<C Any>the maximum element, or default if the input is empty

Examples

ProgramTypeValueError
["abc", "b", "ab"] max(bytes len, <, "")Str"abc"

min

Finds the minimum element.

TypeValue
InputArr<<A Any>...>an array
less (param #1)for <A Any> (<A Any>) Boolfuncer that tests whether its input is "less than" its first argument
default (param #2)<B Any>default value to return if the input is empty
Output<A Any>|<B Any>the minimum element, or default if the input is empty

Examples

ProgramTypeValueError
["abc", "b", "ab"] min(<, "")Str"ab"

min

Finds the minimum element according to a sorting key.

TypeValue
InputArr<<A Any>...>an array
sortKey (param #1)for <A Any> <B Any>funcer that maps input elements to values by which they will be compared
less (param #2)for <B Any> (<B Any>) Boolfuncer that tests whether its input is "less than" its first argument
default (param #3)<C Any>default value to return if the input is empty
Output<A Any>|<C Any>the minimum element, or default if the input is empty

Examples

ProgramTypeValueError
["abc", "b", "ab"] min(bytes len, <, "")Str"b"

range

Builds a range of numbers

TypeValue
InputAnyany value (is ignored)
from (param #1)Numlower limit (inclusive)
to (param #2)Numupper limit (inclusive)
OutputArr<Num...>an array with the integers in the specified interval

Examples

ProgramTypeValueError
range(0, 4)Arr<Num...>[0, 1, 2, 3]
range(-1, 2)Arr<Num...>[-1, 0, 1]
range(3, 2)Arr<Num...>[]

repeat

Concatenates an array with copies of itself.

TypeValue
InputArr<<A Any>...>an array
times (param #1)Numhow many times to repeat the input
OutputArr<<A Any>...>the elements of the input repeated times times in a single array

Examples

ProgramTypeValueError
[1, 2, 3] repeat(3)Arr<Num...>[1, 2, 3, 1, 2, 3, 1, 2, 3]
[1, 2, 3] repeat(0)Arr<Num...>[]
[1, 2, 3] repeat(1)Arr<Num...>[1, 2, 3]

rev

Reverses an array.

TypeValue
InputArr<<A Any>...>an array
OutputArr<<A Any>...>the input in reverse order

Examples

ProgramTypeValueError
[1, 2, 3] revArr<Num...>[3, 2, 1]
[] revArr<>[]

some

Checks if some element is true.

TypeValue
InputArr<Bool...>an array of boolean values
OutputBooltrue iff at least one element of the input is true

Examples

ProgramTypeValueError
[] someBoolfalse
[false] someBoolfalse
[false, false] someBoolfalse
[false, true, false] someBooltrue

sort

Sorts numbers.

TypeValue
InputArr<Num...>an array of numbers
OutputArr<Num...>the input sorted from smallest to greatest

Examples

ProgramTypeValueError
[7, 3, 2, 5, 2] sortArr<Num...>[2, 2, 3, 5, 7]

sort

Sorts strings.

TypeValue
InputArr<Str...>an array of strings
OutputArr<Str...>the input sorted lexicographically

Examples

ProgramTypeValueError
"Zwölf Boxkämpfer jagen Victor quer über den großen Sylter Deich . Voilà !" fields sortArr<Str...>["!", ".", "Boxkämpfer", "Deich", "Sylter", "Victor", "Voilà", "Zwölf", "den", "großen", "jagen", "quer", "über"]

sort

Sorts values.

TypeValue
InputArr<<A Any>...>an array
less (param #1)for <A Any> (<A Any>) Boolfuncer that tests whether its input is "less than" its first argument
OutputArr<<A Any>...>the input sorted by the given ordering function

Examples

ProgramTypeValueError
[7, 3, 2, 5] sort(>)Arr<Num...>[7, 5, 3, 2]
"Zwölf Boxkämpfer jagen Victor quer über den großen Sylter Deich . Voilà !" fields sort(>)Arr<Str...>["über", "quer", "jagen", "großen", "den", "Zwölf", "Voilà", "Victor", "Sylter", "Deich", "Boxkämpfer", ".", "!"]
[{a: 7}, {a: 3}, {a: 2}, {a: 5}] for Obj<a: Num, Void> def <(other Obj<a: Num, Void>) Bool as @a <(other @a) ok sort(<)Arr<Obj<a: Num, Void>...>[{a: 2}, {a: 3}, {a: 5}, {a: 7}]
[{a: 7, b: 2}, {a: 3, b: 1}, {a: 2, b: 2}, {a: 5, b: 2}] for Obj<a: Num, b: Num, Void> def <(other Obj<a: Num, b: Num, Void>) Bool as @b <(other @b) ok sort(<)Arr<Obj<a: Num, b: Num, Void>...>[{a: 3, b: 1}, {a: 7, b: 2}, {a: 2, b: 2}, {a: 5, b: 2}]

sortBy

Sorts an array with a sorting key.

TypeValue
InputArr<<A Any>...>an array
sortKey (param #1)for <A Any> <B Any>funcer that maps input elements to values by which they will be compared
less (param #2)for <B Any> (<B Any>) Boolfuncer that tests whether its input is "less than" its first argument
OutputArr<<A Any>...>the input sorting according to the given sorting key and ordering function

Examples

ProgramTypeValueError
[{a: 7}, {a: 3}, {a: 2}, {a: 5}] sortBy(@a, <)Arr<Obj<a: Num, Void>...>[{a: 2}, {a: 3}, {a: 5}, {a: 7}]
[{a: 7, b: 2}, {a: 3, b: 1}, {a: 2, b: 2}, {a: 5, b: 2}] sortBy(@b, <)Arr<Obj<a: Num, b: Num, Void>...>[{a: 3, b: 1}, {a: 7, b: 2}, {a: 2, b: 2}, {a: 5, b: 2}]

take

Takes the first n elements from an array.

TypeValue
InputArr<<A Any>...>an array
n (param #1)Numnumber of elements to take
OutputArr<<A Any>...>array with the first n elements from the input

Examples

ProgramTypeValueError
[1, 2, 3] take(2)Arr<Num...>[1, 2]
[1, 2, 3] take(1)Arr<Num...>[1]
[1, 2, 3] take(0)Arr<Num...>[]
[1, 2, 3] take(-1)Arr<Num...>[]
[1, 2, 3] take(4)Arr<Num...>[1, 2, 3]
[1, 2, 3] take(3)Arr<Num...>[1, 2, 3]

takeWhile

Takes elements from the beginning of an array that satisfy a certain predicate.

TypeValue
InputArr<<A Any>...>an array
predicate (param #1)for <A Any> Obj<yes: <B Any>, Any>|Obj<no: <C Any>, Any>a predicate to apply to elements of the input
OutputArr<<B Any>...>an array with the elements that satisfy the predicate, up to and excluding the first one that doesn't

Examples

ProgramTypeValueError
[1, 3, 5, 2, 4, 7] takeWhile(if %2 ==1)Arr<Num...>[1, 3, 5]
[1, 3, 5, 2, 4, 7] takeWhile(if %2 ==0)Arr<Num...>[]
[{a: 1}, {a: 2}, {b: 3}, {a: 4}] takeWhile(is {a: _}) each(@a)Arr<Num...>[1, 2]