Array
/=
(λ [(Ref (Array a)), (Ref (Array a))] Bool)
(/= a b)
compares two arrays and inverts the result.
all?
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] Bool)
(all? f a)
checks whether all of the elements in a
match the function f
.
allocate
(λ [Int] (Array t))
allocates an uninitialized array. You can initialize members using aset-uninitialized
.
any?
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] Bool)
(any? f a)
checks whether any of the elements in a
match the function f
.
aset
(λ [(Array t), Int, t] (Array t))
sets an array element at the index n
to a new value.
aset!
(λ [(Ref (Array t)), Int, t] ())
sets an array element at the index n
to a new value in place.
aset-uninitialized!
(λ [(Ref (Array t)), Int, t] ())
sets an uninitialized array member. The old member will not be deleted.
aupdate
(λ [(Array a), Int, (Ref (λ [&a] a))] (Array a))
(aupdate a i f)
transmutes (i.e. updates) the element at index i
of an array a
using the function f
.
aupdate!
(λ [(Ref (Array a)), Int, (Ref (λ [&a] a))] ())
(aupdate! a i f)
transmutes (i.e. updates) the element at index i
of an array a
using the function f
in place.
concat
(λ [(Ref (Array (Array a)))] (Array a))
(concat xs)
returns a new array which is the concatenation of the provided nested array xs
.
copy-filter
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] (Array a))
(copy-filter f a)
filters the elements in an array.
It will create a copy. If you want to avoid that, consider using endo-filter
instead.
copy-map
(λ [(Ref (λ [&a] b)), (Ref (Array a))] (Array b))
(copy-map f a)
maps over an array a
using the function f
.
This function copies the array. If you don’t want that, use endo-map
.
delete
(λ [(Array a)] ())
deletes an array. This function should usually not be called manually.
element-count
(λ [(Ref (Array a)), &a] Int)
(element-count a e)
counts the occurrences of element e
in an array.
endo-filter
(λ [(Ref (λ [&a] Bool)), (Array a)] (Array a))
filters array members using a function. This function takes ownership.
endo-map
(λ [(Ref (λ [a] a)), (Array a)] (Array a))
applies a function f
to an array a
. The type of the elements cannot change.
enumerated
(λ [(Ref (Array a))] (Array (Pair Int a)))
(enumerated xs)
creates a new array of Pair
s where the first position is the index and the second position is the element from the original array xs
.
find
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] (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
(λ [(Ref (λ [&a] Bool)), (Ref (Array a))] (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
(λ [(Ref (Array a))] (Maybe a))
(first a)
takes the first element of an array and returns a Just
.
Returns Nothing
if the array is empty.
index-of
(λ [(Ref (Array a)), &a] (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
(λ [(Ref (Array a))] (Maybe a))
(last a)
takes the last element of an array and returns a Just
.
Returns Nothing
if the array is empty.
maximum
(λ [(Ref (Array a))] (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
(λ [(Ref (Array a))] (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
pop-back
(λ [(Array a)] (Array a))
removes the last element of an array and returns the new array.
pop-back!
(λ [(Ref (Array a))] a)
removes an element value
from the end of an array a
in-place and returns it.
predicate-count
(λ [(Ref (Array a)), (Ref (λ [&a] Bool))] Int)
(predicate-count a pred)
counts the number of elements satisfying the predicate function pred
in an array.
prefix-array
(λ [(Ref (Array a)), Int] (Array a))
(prefix-array xs end-index)
gets a prefix array to end-index
.
push-back!
(λ [(Ref (Array a)), a] ())
adds an element value
to the end of an array a
in-place.
range
(λ [a, a, a] (Array a))
(range start end step)
creates an array from start
to end
with step
between them (the elements must support <
, <=
, >=
, and to-int
).
raw
(λ [(Array t)] (Ptr t))
returns an array a
as a raw pointer—useful for interacting with C.
reduce
(λ [(Ref (λ [a, &b] a)), a, (Ref (Array b))] a)
(reduce f x xs)
will reduce an array xs
into a single value using a function f
that takes the reduction thus far and the next value. The initial reduction value is x
.
As an example, consider this definition of sum
based on reduce
:
(defn sum [x]
(reduce + 0 x))
It will sum the previous sum with each new value, starting at 0
.
remove
(λ [&a, (Array a)] (Array a))
(remove el arr)
removes all occurrences of the element el
in the array arr
, in place.
remove-nth
(λ [Int, (Array a)] (Array a))
(remove-nth i arr)
removes element at index idx
from the array arr
.
repeat
(λ [Int, (Ref (λ [] a))] (Array a))
(repeat n f)
repeats the function f
n
times and stores the results in an array.
repeat-indexed
(λ [Int, (λ [Int] a)] (Array a))
(repeat-indexed n f)
repeats function f
n
times and stores the results in an array.
This is similar to repeat
, but the function f
will be supplied with the index of the element.
replicate
(λ [Int, &a] (Array a))
(replicate n e)
repeats element e
n
times and stores the results in an array.
sort-by
(λ [(Array a), (Ref (λ [&a, &a] Bool))] (Array a))
(sort-by arr f)
Perform an in-place heapsort of a given owned array by a comparison function.
sort-by!
(λ [(Ref (Array a)), (Ref (λ [&a, &a] Bool))] ())
(sort-by! arr f)
Perform an in-place heapsort of a given array by a comparison function.
sorted
(λ [(Ref (Array a))] (Array a))
(sorted arr)
Perform a heapsort in a new copy of given array.
sorted-by
(λ [(Ref (Array a)), (Ref (λ [&a, &a] Bool))] (Array a))
(sorted-by arr f)
Perform a heapsort in a new copy of given array by a comparison function.
subarray
(λ [(Ref (Array a)), Int, Int] (Array a))
(subarray xs start-index end-index)
gets a subarray from start-index
to end-index
.
suffix-array
(λ [(Ref (Array a)), Int] (Array a))
(suffix-array xs start-index)
gets a suffix array from start-index
.
sum-length
(λ [(Ref (Array (Array a)))] Int)
(sum-length xs)
returns the sum of lengths from a nested array xs
.
swap!
(λ [(Ref (Array a)), Int, Int] ())
(swap! a i j)
swaps the indices i
and j
of an array a
in place.
unsafe-first
(λ [(Ref (Array a))] a)
(unsafe-first a)
takes the first element of an array.
Generates a runtime error if the array is empty.
unsafe-last
(λ [(Ref (Array a))] a)
(unsafe-last a)
takes the last element of an array.
Generates a runtime error if the array is empty.
zip
(λ [(Ref (λ [&a, &b] c)), (Ref (Array a)), (Ref (Array b))] (Array c))
(zip f a b)
maps over two arrays using a function f
that takes two arguments. It will produces a new array with the length of the shorter input.
The trailing elements of the longer array will be discarded.