This module introduces the StaticArray. A static array is a non empty array fix a fixed size.
We can check the size in compile-time and ensure that the array is about as fast as a usual (dynamic) array in run time.
Constructs an array from a list
Gets an element of the array. Note that it only possible if the index is in bound. Therefore eliminating Off-by-one errors.
Sets an element of the array.
Returns the length of an array.
Changes the size of the array. If the array gets bigger, then the first element of the array gets used as default value.
singleton 42
|> push 7
|> resize (Length.one |> Length.plus4)
|> toArray
|> Array.toList --> [42,7,42,42,42]Transforms the static array into a dynamic array.
Updates all elements of an array.
Same as map but with an index.
Exposes the underlying record of the array
array =
[0,1,2,3,4,5]
|> fromList (Length.five |> Length.plus1 )
array |> toRecord |> fromRecord --> arrayConstructs a static array from its components. If the Length is bigger then the number of elements provided, the additional element will be filled with duplicates of head.
fromRecord
{ length = (Length.five |> Length.plus1 )
, head = 0
, tail = [1,2,3,4,5]
}
--> fromList (Length.five |> Length.plus1 ) [0,1,2,3,4,5]
A static array is an array with a fixed length.