StaticArray
is a data type for static, immutable arrays. They are
stack-allocated. For a more flexible, heap-allocated version, you might want to look at the Array
module.
=
(Fn [(Ref (StaticArray a) b), (Ref (StaticArray a) b)] Bool)
(= a b)
compares two static arrays.
all?
(Fn [(Ref (Fn [(Ref a b)] Bool c) d), (Ref (StaticArray a) b)] Bool)
(all? f a)
checks whether all of the elements in a
match the function f
.
any?
(Fn [(Ref (Fn [(Ref a b)] Bool c) d), (Ref (StaticArray a) b)] Bool)
(any? f a)
checks whether any of the elements in a
match the function f
.
aset!
(Fn [(Ref (StaticArray a) b), Int, a] ())
sets a static array element at the index n
to a new value in place.
aset-uninitialized!
(Fn [(Ref (StaticArray a) b), Int, a] ())
sets an uninitialized static array member. The old member will not be deleted.
aupdate!
(Fn [(Ref (StaticArray a) b), Int, (Ref (Fn [a] a c) d)] ())
(aupdate! a i f)
transmutes (i.e. updates) the element at index i
of an array a
using the function f
in place.
contains?
(Fn [(Ref (StaticArray a) b), (Ref a b)] Bool)
(contains? arr el)
checks wether an element exists in the array.
delete
(Fn [(StaticArray a)] ())
deletes a static array. This function should not be called manually (there shouldn't be a way to create value types of type StaticArray).
element-count
(Fn [(Ref (StaticArray a) b), (Ref a b)] Int)
(element-count a e)
counts the occurrences of element e
in an array.
find
(Fn [(Ref (Fn [(Ref a b)] Bool c) d), (Ref (StaticArray a) b)] (Maybe a))
(find f a)
finds an element in a
that matches the function f
and wraps it in a Just
.
If it doesn’t find an element, Nothing
will be returned.
find-index
(Fn [(Ref (Fn [(Ref a b)] Bool c) d), (Ref (StaticArray a) b)] (Maybe Int))
(find-index f a)
finds the index of the first element in a
that matches the function f
and wraps it in a Just
.
If it doesn’t find an index, Nothing
will be returned.
first
(Fn [(Ref (StaticArray a) b)] (Maybe a))
(first a)
takes the first element of an array and returns a Just
.
Returns Nothing
if the array is empty.
index-of
(Fn [(Ref (StaticArray a) b), (Ref a b)] (Maybe Int))
(index-of a e)
gets the index of element e
in an array and wraps it on a Just
.
If the element is not found, returns Nothing
last
(Fn [(Ref (StaticArray a) b)] (Maybe a))
(last a)
takes the last element of an array and returns a Just
.
Returns Nothing
if the array is empty.
map!
(Fn [(Ref (StaticArray a) b), (Ref (Fn [(Ref a b)] a c) d)] ())
(map! xs f)
Maps a function over the static array xs
, mutating it in place. The difference to Array.endo-map (which does the same thing internally) is that this function takes a ref (since you can never have static arrays as values) and that it returns ().
maximum
(Fn [(Ref (StaticArray a) b)] (Maybe a))
(maximum xs)
gets the maximum in an array (elements must support <
) and wraps it in a Just
.
If the array is empty, it returns Nothing
.
minimum
(Fn [(Ref (StaticArray a) b)] (Maybe a))
(minimum xs)
gets the minimum in an array (elements must support >
) and wraps it in a Just
.
If the array is empty, returns Nothing
nth
(Fn [(Ref (StaticArray a) b), Int] (Maybe a))
(nth xs index)
gets a reference to the n
th element from an array arr
wrapped on a Maybe
.
If the index
is out of bounds, return Maybe.Nothing
predicate-count
(Fn [(Ref (StaticArray a) b), (Ref (Fn [(Ref a b)] Bool c) d)] Int)
(predicate-count a pred)
counts the number of elements satisfying the predicate function pred
in an array.
scan!
(Fn [(Ref (Fn [a, a] a b) c), (Ref (StaticArray a) d)] ())
(scan! f xs)
Scans and replaces the array in-place, using a binary function.
For example, give (def numbers [1 1 1])
, a scan!
using Int.+
will mutate numbers
to be [1 2 3]
.
sum
(Fn [(Ref (StaticArray a) b)] a)
(sum xs)
sums an array (elements must support +
and zero
).
swap!
(Fn [(Ref (StaticArray a) b), Int, Int] ())
(swap! a i j)
swaps the indices i
and j
of an array a
in place.
unsafe-first
(Fn [(Ref (StaticArray a) b)] a)
(unsafe-first a)
takes the first element of an array.
Generates a runtime error if the array is empty.
unsafe-last
(Fn [(Ref (StaticArray a) b)] a)
(unsafe-last a)
takes the last element of an array.
Generates a runtime error if the array is empty.
unsafe-nth
(Fn [(Ref (StaticArray a) b), Int] (Ref a b))
gets a reference to the n
th element from a static array a
.
unsafe-nth-value
(Fn [(Ref (StaticArray a) b), Int] a)
returns the value at index i
of a static array a
(just like unsafe-nth) but does not take its reference, and does not copy the value. Should only be used for optimizations and when you know what you're doing, circumvents the borrow checker!
unsafe-raw
(Fn [(Ref (StaticArray a) b)] (Ptr a))
returns an array a as a raw pointer—useful for interacting with C.