CX · Reference guidearray
PlaygroundDownloadsAboutv0.17.0

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: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: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) -> array — Ascending by the language's one sort arrangement — the [\$sort] comparator (kind-class, then value).

      [?lib 'cx-stdlib/array']
[$array:sort [3, 1, 2]]
    
      [1, 2, 3]
    

array:filter

[$array:filter] (a::array, fn::any) -> array — The items for which the one-parameter predicate answers true, order preserved.

      [?lib 'cx-stdlib/array']
[$array:filter [1, 2, 3, 4] [?fn ($x) [> $x 2]]]
    
      [3, 4]
    

array:for-each

[$array:for-each] (a::array, fn::any) -> array — A new array of the function applied to each item, order preserved.

      [?lib 'cx-stdlib/array']
[$array:for-each [1, 2, 3] [?fn ($x) [* $x 10]]]
    
      [10, 20, 30]
    

array:fold-left

[$array:fold-left] (a::array, init::any, fn::any) -> 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::any) -> 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