Arrays

Module arrays

import arrays

Eager operations over Array.

arrays operates on the built-in prelude.Array type. Every function returns a new array rather than changing the one passed in.

These are the eager versions: each one walks the whole array and builds its result immediately. For the same operations applied lazily to anything iterable, see fun.

Dependencies


Contents


Functions

concat

`arrays/arrays.zirr:32`
fn concat(parts: [[Any]]) -> [Any]

Concatenates every array in parts into a single array, in order. Unlike
append(), which adds each argument as one new element, this flattens one
level — concat([[1, 2], [3]]) is [1, 2, 3], not [[1, 2], [3]].


contains

`arrays/arrays.zirr:88`
fn contains(v: [Any], value: Any) -> Bool

Returns whether value occurs anywhere in v.


filter

`arrays/arrays.zirr:138`
fn filter(v: [Any], predicate: fn(Any) -> Bool) -> [Any]

Returns a new array containing only the elements of v for which predicate
returns true, in order.


first

`arrays/arrays.zirr:72`
fn first(v: [Any]) -> Option

Returns v’s first element, or None if v is empty.


firstIndexOf

`arrays/arrays.zirr:93`
fn firstIndexOf(v: [Any], value: Any) -> Option

Returns the index of value’s first occurrence in v, or None if absent.


flatMap

`arrays/arrays.zirr:126`
fn flatMap(v: [Any], transform: fn(Any) -> [Any]) -> [Any]

Returns a new array with transform applied to each element of v, flattening each resulting array one level into the result.


isEmpty

`arrays/arrays.zirr:67`
fn isEmpty(v: [Any]) -> Bool

Returns whether v has no elements.


last

`arrays/arrays.zirr:80`
fn last(v: [Any]) -> Option

Returns v’s last element, or None if v is empty.


lastIndexOf

`arrays/arrays.zirr:105`
fn lastIndexOf(v: [Any], value: Any) -> Option

Returns the index of value’s last occurrence in v, or None if absent.


map

`arrays/arrays.zirr:117`
fn map(v: [Any], transform: fn(Any) -> Any) -> [Any]

Returns a new array with transform applied to each element of v, in order.


range

`arrays/arrays.zirr:18`
fn range(v: [Any], r: ranges.Like) -> [Any]

Returns the elements of v selected by r.


reduce

`arrays/arrays.zirr:150`
fn reduce(v: [Any], initial: Any, combine: fn(Any, Any) -> Any) -> Any

Combines v’s elements into a single value, starting from initial and
applying combine(accumulator, element) left to right.


repeat

`arrays/arrays.zirr:43`
fn repeat(v: [Any], n: Int) -> [Any]

Returns v repeated n times, concatenated.


reverse

`arrays/arrays.zirr:56`
fn reverse(v: [Any]) -> [Any]

Returns v with its elements in reverse order.


slice

`arrays/arrays.zirr:6`
fn slice(v: [Any], start: Int, end: Int) -> [Any]

Returns the elements of v from start (inclusive) to end (exclusive).