squiggle/packages/website/docs/Api/List.md

1.5 KiB

sidebar_position title
7 List

make

List.make: (number, 'a) => list<'a>

Returns an array of size n filled with value e.

List.make(4, 1) // creates the list [1, 1, 1, 1]

See Rescript implementation

toString

toString: (list<'a>) => string

length

length: (list<'a>) => number

up to

List.upTo: (low:number, high:number) => list<number>
List.upTo(0, 5) // creates the list [0, 1, 2, 3, 4, 5]

Syntax taken from Ruby.

first

first: (list<'a>) => 'a

last

last: (list<'a>) => 'a

reverse

reverse: (list<'a>) => list<'a>

map

map: (list<'a>, a => b) => list<'b>

See Rescript implementation.

reduce

reduce: (list<'b>, 'a, ('a, 'b) => 'a) => 'a 

reduce(arr, init, f)

Applies f to each element of arr. The function f has two paramaters, an accumulator and the next value from the array.

reduce([2, 3, 4], 1, {|acc, value| acc + value}) == 10

See Rescript implementation.

reduce reverse

reduceReverse: (list<'b>, 'a, ('a, 'b) => 'a) => 'a 

Works like reduce, but the function is applied to each item from the last back to the first.

See Rescript implementation.