Array

GitHub   Edit on GitHub

Utilities for working with arrays.

1
import Array from 'arrays'

Values

Array.length

1
length : Array<a> -> Number

Returns the length of the input array.

Array.make

1
make : (Number, a) -> Array<a>

make(n, value) creates a new array of length n filled with value.

1
Array.make(5, 'foo') # [> 'foo', 'foo', 'foo', 'foo', 'foo']

Array.init

1
init : (Number, Number -> a) -> Array<a>

Similar to make, but each array value is initialized with the result of subsequent calls to the given initializer function. The initializer is called with the index of each array slot.

1
Array.init(5, n => n + 3) # [> 8, 9, 10, 11, 12]

Array.get

1
get : (Number, Array<a>) -> a

An alias for normal syntactic array access, i.e. array[n].

Array.get(n, array) retrieves the nth item from the array. A negative n is treated as an offset from the end of the array.

Array.set

1
set : (Number, a, Array<a>) -> a

An alias for normal syntactic array set, i.e. array[n] := value.

Array.set(n, value, array) sets the nth slot in the array to value. A negative n is treated as an offset from the end of the array. Returns the newly set item.

Array.append

1
append : (Array<a>, Array<a>) -> Array<a>

Array.append(array1, array2) creates a new array with the items of array1 followed by the items of array2. This does not modify array1 or array2.

Array.concat

1
concat : List<Array<a>> -> Array<a>

Takes a list of arrays and creates a single array containing the elements of all of the arrays. Does not modify any of the input arrays.

Array.copy

1
copy : Array<a> -> Array<a>

Produces a copy of the input array.

Array.forEach

1
forEach : (a -> Void, Array<a>) -> Void

Array.forEach(fn, array) calls fn on each element of the array.

Array.forEachi

1
forEachi : ((a, Number) -> Void, Array<a>) -> Void

Array.forEachi(fn, array) calls fn on each element of the array, along with the index of the element.

Array.map

1
map : (a -> b, Array<a>) -> Array<b>

Array.map(fn, array) produces a new array by calling fn on each element of the input array.

Array.mapi

1
mapi : ((a, Number) -> b, Array<a>) -> Array<b>

Array.mapi(fn, array) produces a new array by calling fn on each element of the input array along with its index.

Array.toList

1
toList : Array<a> -> List<a>

Converts the input array to a list.

Array.fromList

1
fromList : List<a> -> Array<a>

Converts the input list to an array.

Array.contains

1
contains : (a, Array<a>) -> Bool

Checks if the item is an element of the input array. Uses the generic == structural equality operator.

This is a notification!