array
Bundled cx-stdlib module.
array:size
[$array:size] (a::array) -> int — The item count.
[?lib 'cx-stdlib/array']
[$array:size [10, 20, 30]]
3
array:get
[$array:get] (a::array, i::int) -> any — The item at 1-based position i; out of range refuses loudly.
[?lib 'cx-stdlib/array']
[$array:get [10, 20, 30] 2]
20
array:head
[$array:head] (a::array) -> any — The first item; the empty array yields the empty sequence.
[?lib 'cx-stdlib/array']
[$array:head [10, 20]]
10
array:tail
[$array:tail] (a::array) -> array — Everything after the first item; the empty array's tail is the empty array.
[?lib 'cx-stdlib/array']
[$array:tail [10, 20, 30]]
[20, 30]
array:last
[$array:last] (a::array) -> any — The last item — the top of a stack; the empty array yields the empty sequence, as head does.
[?lib 'cx-stdlib/array']
[$array:last [10, 20, 30]]
30
array:pop
[$array:pop] (a::array) -> array — Everything before the last item — a stack with its top dropped; the empty array's pop is the empty array, as its tail is.
[?lib 'cx-stdlib/array']
[$array:pop [10, 20, 30]]
[10, 20]
array:append
[$array:append] (a::array, v::any) -> array — A new array with the value as the last item.
[?lib 'cx-stdlib/array']
[$array:append [1, 2] 3]
[1, 2, 3]
array:reverse
[$array:reverse] (a::array) -> array — The items in reverse order.
[?lib 'cx-stdlib/array']
[$array:reverse [1, 2, 3]]
[3, 2, 1]
array:subarray
[$array:subarray] (a::array, start::int, len::int) -> array — len items starting at 1-based start, clamped to the array's end.
[?lib 'cx-stdlib/array']
[$array:subarray [10, 20, 30, 40] 2 2]
[20, 30]
array:put
[$array:put] (a::array, i::int, v::any) -> array — A new array with 1-based position i replaced by the value; out of range refuses.
[?lib 'cx-stdlib/array']
[$array:put [1, 2, 3] 2 9]
[1, 9, 3]
array:remove
[$array:remove] (a::array, i::int) -> array — A new array without 1-based position i; out of range refuses.
[?lib 'cx-stdlib/array']
[$array:remove [1, 2, 3] 2]
[1, 3]
array:insert-before
[$array:insert-before] (a::array, i::int, v::any) -> array — A new array with the value inserted before 1-based position i; i = size + 1 appends.
[?lib 'cx-stdlib/array']
[$array:insert-before [1, 3] 2 2]
[1, 2, 3]
array:flatten
[$array:flatten] (a::any) -> any — The sequence of leaf items with every nested array and boxed sequence expanded, depth-first.
[?lib 'cx-stdlib/array']
[$array:flatten [1, [2, [3]], 4]]
(1, 2, 3, 4)
array:zip
[$array:zip] (a::array b::array) -> array — The pairs of two arrays of equal size, in order, as an array of 2-item arrays; arrays of different sizes refuse, naming both.
[?lib 'cx-stdlib/array']
[$array:zip ['alpha', 'beta', 'gamma'] [7, 42, 13]]
[['alpha', 7], ['beta', 42], ['gamma', 13]]
array:join
[$array:join] (arrays::any) -> array — A sequence of arrays concatenated left to right into one array.
[?lib 'cx-stdlib/array']
[$array:join ([1, 2], [3])]
[1, 2, 3]
array:sort
[$array:sort] (a::array, opts?) -> array — Ascending by the language's one sort arrangement — the [\$sort] comparator (kind-class, then value). An options map {order: :desc} sorts descending (GAPS-1).
[?lib 'cx-stdlib/array']
[$array:sort [3, 1, 2]]
[1, 2, 3]
array:filter
[$array:filter] (a::array, fn::function) -> array — The items for which the one-parameter predicate answers true, order preserved.
[?lib 'cx-stdlib/array']
[$array:filter [1, 2, 3, 4] [> _ 2]]
[3, 4]
array:bisect-left
[$array:bisect-left] (a::array, x::any, opts::map) -> int — Binary search over an ascending array: the first 1-based position whose item is x or more (size + 1 past the end), as Python's bisect_left; an optional {key: FN} reads each item, never x.
[?lib 'cx-stdlib/array']
[$array:bisect-left [1, 3, 5] 4]
3
array:bisect-right
[$array:bisect-right] (a::array, x::any, opts::map) -> int — Binary search over an ascending array: the first 1-based position whose item is more than x (size + 1 past the end), as Python's bisect_right; an optional {key: FN} reads each item, never x.
[?lib 'cx-stdlib/array']
[$array:bisect-right [1, 2, 2, 5] 2]
4
array:for-each
[$array:for-each] (a::array, fn::function) -> array — A new array of the function applied to each item, order preserved.
[?lib 'cx-stdlib/array']
[$array:for-each [1, 2, 3] [* _ 10]]
[10, 20, 30]
array:fold-left
[$array:fold-left] (a::array, init::any, fn::function) -> any — Fold left: fn(fn(init, a1), a2)… — fn takes (accumulator, item).
[?lib 'cx-stdlib/array']
[$array:fold-left [1, 2, 3] 0 [?fn ($acc $x) [+ $acc $x]]]
6
array:fold-right
[$array:fold-right] (a::array, init::any, fn::function) -> any — Fold right: fn(a1, fn(a2, … init)) — fn takes (item, accumulator).
[?lib 'cx-stdlib/array']
[$array:fold-right [1, 2, 3] 0 [?fn ($x $acc) [- $x $acc]]]
2
array:combinations
[$array:combinations] (a::array, k::int) -> array — The k-element combinations, each an array of the items in their array order, in lexicographic order of positions; k = 0 is [[]], k past the size is [].
[?lib 'cx-stdlib/array']
[$array:combinations [1, 2, 3] 2]
[[1, 2], [1, 3], [2, 3]]
array:permutations
[$array:permutations] (a::array) -> array — Every ordering of the items, each an array, in lexicographic order of positions; the empty array has the one empty ordering [[]].
[?lib 'cx-stdlib/array']
[$array:permutations [1, 2]]
[[1, 2], [2, 1]]
array:k-permutations
[$array:k-permutations] (a::array, k::int) -> array — Every ordering of k of the items, each an array, in lexicographic order of positions; k = 0 is [[]], k past the size is [].
[?lib 'cx-stdlib/array']
[$array:k-permutations [1, 2, 3] 2]
[[1, 2], [1, 3], [2, 1], [2, 3], [3, 1], [3, 2]]
array:windows
[$array:windows] (a::array, k::int) -> array — The overlapping runs of k adjacent items, each an array, in order; none when k is past the size; k < 1 refuses.
[?lib 'cx-stdlib/array']
[$array:windows [1, 2, 3, 4] 2]
[[1, 2], [2, 3], [3, 4]]
array:partition-by
[$array:partition-by] (a::array, fn::function) -> array — The runs of consecutive items whose key (fn of the item) is equal, each an array, in order; a key recurring after another starts a new run.
[?lib 'cx-stdlib/array']
[$array:partition-by ['a', 'a', 'b', 'a'] [?fn ($c) $c]]
[['a', 'a'], ['b'], ['a']]