FrozenArray

lib/FrozenArray.gob

No module comment.

type FrozenArray a

An array that nobody can write: its length and its elements are fixed when it is made. Equal frozen arrays hash alike, so one can be a Map key or a Set element, which a mutable Array cannot. The freezing is shallow: which elements it holds is fixed, but an element that is itself mutable can still change, and a key holding one can be lost as a mutable key is.

Its one field is not exported, and no function here writes to storage it has wrapped, so module privacy is the whole guarantee. That holds only while every function that makes one wraps storage nothing else holds: freeze copies, because its caller keeps the source.

An array literal the program uses as a FrozenArray is built as this constructor applied to the literal's fresh storage, by name; renaming it means changing how the compiler lowers a literal in the same commit. A frozen array is a value, as a string is: nothing can tell two with the same elements apart, so a literal could later be a shared constant. !Object keeps identical off it.

fun freeze : [Iterator c, Length c, Item c ~ a] fun(c) -> FrozenArray a

Returns a frozen copy of the elements of xs, in iteration order. Copies, so later writes to xs do not show. xs is anything with a length that can be iterated, such as an Array, a Vec or a Deque.

fun toArray : fun(FrozenArray a) -> Array a

Returns a new, writable Array of the same elements.

fun toVec : fun(FrozenArray a) -> Vec a

Returns a new Vec of the same elements.

fun filled : fun(Int, a) -> FrozenArray a

Returns a frozen array of length elements, each value.

fun init : fun(Int, fun(Int) -> a) -> FrozenArray a

Returns a frozen array whose element i is f(i), computed in order from 0.

fun with : fun(FrozenArray a, Int, a) -> FrozenArray a

Returns a copy of xs with element i replaced by x. Copies once, so it is the way to make a neighbouring state: building an Array and freezing it copies twice. Panics unless 0 <= i < len(xs).

fun at : fun(FrozenArray a, Int) -> Option a

Returns Some of element i, or None when i is not an index of xs.

fun last : fun(FrozenArray a) -> Option a

Returns Some of the last element, or None when xs is empty.

fun slice : fun(FrozenArray a, Int, Int) -> FrozenArray a

Returns the elements from index from up to but not including to. Panics unless 0 <= from <= to <= len(xs).

fun append : fun(FrozenArray a, FrozenArray a) -> FrozenArray a

Returns the elements of xs followed by those of ys.

fun map : fun(FrozenArray a, fun(a) -> b) -> FrozenArray b

Returns f of each element, in order.

fun filter : fun(FrozenArray a, fun(a) -> Bool) -> FrozenArray a

Returns the elements for which keep is true, in order. keep is called once per element, in order.

fun fold : fun(FrozenArray a, b, fun(b, a) -> b) -> b

Returns step applied to initial and each element in turn.

fun reverse : fun(FrozenArray a) -> FrozenArray a

Returns the elements in reverse order.

fun indexOf : [Eq a] fun(FrozenArray a, a) -> Option Int

Returns the index of the first element equal to wanted, or None.

fun contains : [Eq a] fun(FrozenArray a, a) -> Bool

Returns whether some element equals wanted.

fun sortBy : fun(FrozenArray a, fun(a, a) -> Ordering) -> FrozenArray a

Returns the elements sorted by compare. The sort is stable.

fun sort : [Ord a] fun(FrozenArray a) -> FrozenArray a

Returns the elements in ascending order. The sort is stable.

fun sortByKey : [Ord k] fun(FrozenArray a, fun(a) -> k) -> FrozenArray a

Returns the elements sorted by key. The sort is stable, and key is called exactly once per element.

instance Index (FrozenArray a)
instance Length (FrozenArray a)
instance Iterator (FrozenArray a)
instance Add (FrozenArray a)
instance Semigroup (FrozenArray a)
instance Monoid (FrozenArray a)
instance Foldable FrozenArray
instance Functor FrozenArray
instance Applicative FrozenArray
instance Monad FrozenArray
instance Eq (FrozenArray a) : Eq a

Equal when they have the same length and equal elements at each index.

instance Ord (FrozenArray a) : Ord a

Lexicographic: the first unequal element decides, and a proper prefix is less than the longer array.

instance Hash (FrozenArray a) : Hash a

The length, then each element in order. The length goes first so that nested arrays split into parts differently hash differently: [[1], [2, 3]] and [[1, 2], [3]] feed different words.

instance Debug (FrozenArray a) : Debug a

Its elements, as the array literal that builds it.

instance Show (FrozenArray a) : Debug a