Array module
This module contains functions for manipulating and inspecting arrays. All of the functions will work on arrays of any type.
It is automatically imported (via the Prelude module) unless
the -noprelude compiler option is used. Almost all programs
and modules will need to import this module.
Exceptions
- OutOfBounds - Attempt to access an out-of-bounds element.
- ZeroStep - The step in a range may not be zero
Functions
- Void addAt(var [a] array,a elem,Int idx) - Add an element to an array
- Bool all(Bool(a) pred,[a] xs) - Check if all elements satisfy a predicate
- Bool any(Bool(a) pred,[a] xs) - Check if any elements satisfy a predicate
- Void concat(var [a] xs,[a] ys) - Concatenate two arrays.
- [a] createArray(Int size) - Create an array
- Bool elem(a val,[a] list,Bool(a, a) eq=equal) - Check whether a value is in a list.
- [a] filter(Bool(a) p,[a] xs) - Filter a list according to a predicate.
- b fold(b(a, b) f,[a] xs,b acc) - Fold an array.
- [a] intersperse(a sep,[a] xs) - Place a separator between each element of an array
- [a] join([[a]] lists) - Concatentate a list of lists
- [b] map(b(a) f,[a] xs) - Map a function across an array.
- Void nub(var [a] xs,Bool(a, a) eq=equal) - Remove repeated elements from a list.
- Void pop(var [a] array) - Remove a value from the end of an array
- Void push(var [a] array,a v) - Push a value onto the end of an array.
- [Int] range(Int first,Int last,Int step=1) - Get a range of integers
- [a] remove([a] array,Int pos,Int n) - Return the array created by removing a subarray.
- Void removeAt(var [a] array,Int idx) - Remove an element from an array
- Void resize(var [a] xs,Int i) - Resize an array.
- Void reverse(var [a] xs) - Reverse an array in-place.
- a shift(var [a] array) - Get the first item off an array, and remove it from the array.
- Void shuffle(var [a] xs) - Randomly reorder an array.
- Void sort(var [a] xs,Int(a, a) sortfn=compare) - Sort an array.
- [a] sorted([a] xs,Int(a, a) sortfn=compare) - Return a sorted array.
- [a] subarray([a] array,Int pos,Int n) - Return a subarray
- [a] take(Int x,[a] xs) - Take the first x elements from an array.
- a top([a] array) - Return the last value in an array
- Void unshift(a val,var [a] array) - Add a value onto the start of an array.
- [Pair<a, b> ] zip([a] xs,[b] ys) - Turn a pair of lists into a list of pairs.
- [c] zipWith(c(a, b) f,[a] xs,[b] ys) - Map a function across two arrays.