Array
Definitions
def
append
[r3ar1r2]
(
rc3 :
Region[r3]
a :
Array[a, r1]
b :
Array[a, r2]
)
: Array[a, r3]
\ r1 + r2 + r3
Return a new array, appending the elements b
to elements of a
.
def
compare
[vr1r2]
(
a :
Array[v, r1]
b :
Array[v, r2]
)
: Comparison
\ r1 + r2
with
Order[v]
Compares a
and b
lexicographically.
def
copyOfRange
[r2ar1]
(
_ :
Region[r2]
b :
Int32
e :
Int32
a :
Array[a, r1]
)
: Array[a, r2]
\ r1 + r2
Copies the range between b
(inclusive) and e
(exclusive) of a into a new array.
A valid range has the following properties:
- 0 <=
b
<=length(a)
. e
>=b
. If the range is valid and greater than the length ofa
, the resulting array with have the length of the range and include the specified range ofa
.
def
count
[aefr]
(
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Int32
\ ef + r
Returns the number of elements in a
that satisfy the predicate f
.
def
drop
[r1ar]
(
rc1 :
Region[r1]
n :
Int32
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Alias for dropLeft
.
def
dropLeft
[r1ar]
(
rc1 :
Region[r1]
n :
Int32
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Returns a copy of array a
, dropping the first n
elements.
Returns []
if n > length(a)
.
def
dropRight
[r1ar]
(
rc1 :
Region[r1]
n :
Int32
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Returns a copy of array a
, dropping the last n
elements.
Returns []
if n > length(a)
.
def
dropWhile
[r1aefr]
(
rc1 :
Region[r1]
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Array[a, r1]
\ ef + r + r1
Alias for dropWhileLeft
.
def
dropWhileLeft
[r1aefr]
(
rc1 :
Region[r1]
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Array[a, r1]
\ ef + r + r1
Returns copy of array a
without the longest prefix that satisfies the predicate f
.
def
dropWhileRight
[r1aefr]
(
rc1 :
Region[r1]
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Array[a, r1]
\ ef + r + r1
Returns copy of array a
without the longest suffix that satisfies the predicate f
.
def
enumerator
[r1ar2]
(
rc :
Region[r1]
a :
Array[a, r2]
)
: Iterator[(Int32, a), r1 + r2, r1]
\ r1
Returns an iterator over a
zipped with the indices of the elements.
Modifying a
while using an iterator has undefined behavior and is dangerous.
def
exists
[aefr]
(
f :
a -> Bool \ ef
arr :
Array[a, r]
)
: Bool
\ ef + r
Returns true
if and only if at least one element in arr
satisfies the predicate f
.
Returns false
if arr
is empty.
def
filter
[r1aefr]
(
rc1 :
Region[r1]
f :
a -> Bool \ ef
arr :
Array[a, r]
)
: Array[a, r1]
\ ef + r + r1
Returns an array of every element in arr
that satisfies the predicate f
.
def
filterMap
[r1aefbr]
(
rc1 :
Region[r1]
f :
a -> Option[b] \ ef
a :
Array[a, r]
)
: Array[b, r1]
\ ef + r + r1
Collects the results of applying the partial function f
to every element in a
.
def
find
[aefr]
(
f :
a -> Bool \ ef
arr :
Array[a, r]
)
: Option[a]
\ ef + r
Alias for findLeft
.
def
findIndexOf
[aefr]
(
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Option[Int32]
\ ef + r
Alias for findIndexOfLeft
.
def
findIndexOfLeft
[aefr]
(
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Option[Int32]
\ ef + r
Optionally returns the position of the first element in x
satisfying f
.
def
findIndexOfRight
[aefr]
(
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Option[Int32]
\ ef + r
Optionally returns the position of the first element in a
satisfying f
searching from right to left.
def
findIndices
[r2aefr1]
(
rc2 :
Region[r2]
f :
a -> Bool \ ef
a :
Array[a, r1]
)
: Array[Int32, r2]
\ ef + r1 + r2
Returns the positions of the all the elements in a
satisfying f
.
def
findLeft
[aefr]
(
f :
a -> Bool \ ef
arr :
Array[a, r]
)
: Option[a]
\ ef + r
Optionally returns the first element of a
that satisfies the predicate f
when searching from left to right.
def
findMap
[aefbr]
(
f :
a -> Option[b] \ ef
a :
Array[a, r]
)
: Option[b]
\ ef + r
Returns the first non-None result of applying the partial function f
to each element of xs
.
Returns None
if every element of xs
is None
.
def
findRight
[aefr]
(
f :
a -> Bool \ ef
arr :
Array[a, r]
)
: Option[a]
\ ef + r
Optionally returns the first element of xs
that satisfies the predicate f
when searching from right to left.
def
flatMap
[r1aefbr]
(
rc1 :
Region[r1]
f :
a -> Array[b, r1] \ ef
a :
Array[a, r]
)
: Array[b, r1]
\ ef + r + r1
Returns the result of applying f
to every element in a
and concatenating the results.
def
flatten
[r1ar]
(
rc1 :
Region[r1]
arrs :
Array[Array[a, r], r]
)
: Array[a, r1]
\ r + r1
Returns the concatenation of the arrays of in the array arrs
.
def
fold
[ar]
(
arr :
Array[a, r]
)
: a
\ r
with
Monoid[a]
Returns the result of applying combine
to all the elements in a
, using empty
as the initial value.
def
fold2
[cabefr1r2]
(
f :
c -> (a -> (b -> c \ ef))
c :
c
a :
Array[a, r1]
b :
Array[b, r2]
)
: c
\ ef + r1 + r2
Alias for foldLeft2
.
def
foldLeft
[baefr]
(
f :
b -> (a -> b \ ef)
s :
b
arr :
Array[a, r]
)
: b
\ ef + r
Applies f
to a start value s
and all elements in a
going from left to right.
That is, the result is of the form: f(...f(f(s, a[0]), a[1])..., xn)
.
def
foldLeft2
[cabefr1r2]
(
f :
c -> (a -> (b -> c \ ef))
c :
c
a :
Array[a, r1]
b :
Array[b, r2]
)
: c
\ ef + r1 + r2
Accumulates the result of applying f
pairwise to the elements of a
and b
starting with the initial value c
and going from left to right.
def
foldMap
[aefbr]
(
f :
a -> b \ ef
arr :
Array[a, r]
)
: b
\ ef + r
with
Monoid[b]
Returns the result of mapping each element and combining the results.
def
foldRight
[abefr]
(
f :
a -> (b -> b \ ef)
s :
b
arr :
Array[a, r]
)
: b
\ ef + r
Applies f
to a start value s
and all elements in a
going from right to left.
That is, the result is of the form: f(a[0], ...f(a[n-1], f(a[n], s))...)
.
def
foldRight2
[abcefr1r2]
(
f :
a -> (b -> (c -> c \ ef))
c :
c
a :
Array[a, r1]
b :
Array[b, r2]
)
: c
\ ef + r1 + r2
Accumulates the result of applying f
pairwise to the elements of a
and b
starting with the initial value c
and going from right to left.
def
foldRightWithCont
[aefrb]
(
f :
a -> ((Unit -> b \ ef + r) -> b \ ef + r)
z :
b
arr :
Array[a, r]
)
: b
\ ef + r
Applies f
to a start value z
and all elements in a
going from right to left.
That is, the result is of the form: f(a[0], ...f(a[n-1], f(a[n], z))...)
.
A foldRightWithCont
allows early termination by not calling the continuation.
def
forAll
[aefr]
(
f :
a -> Bool \ ef
arr :
Array[a, r]
)
: Bool
\ ef + r
Returns true
if and only if all elements in arr
satisfy the predicate f
.
Returns true
if arr
is empty.
def
forEach
[aefr]
(
f :
a -> Unit \ ef
a :
Array[a, r]
)
: Unit
\ ef + r
Apply the effectful function f
to all the elements in the array a
.
def
forEachWithIndex
[aefr]
(
f :
Int32 -> (a -> Unit \ ef)
a :
Array[a, r]
)
: Unit
\ ef + r
Apply the effectful function f
to all the elements in the array a
.
def
get
[ar]
(
i :
Int32
a :
Array[a, r]
)
: a
\ r
Retrieves the value at position i
in the array a
.
def
groupBy
[r1ar2]
(
rc1 :
Region[r1]
f :
a -> (a -> Bool)
a :
Array[a, r2]
)
: Array[Array[a, r1], r1]
\ r2 + r1
Partitions a
into subarrays such that for any two elements x
and y
in a subarray, f(x, y)
is true.
A subarray is created by iterating through the remaining elements of a
from left to right and adding an
element to the subarray if and only if doing so creates no conflicts with the elements already in the subarray.
The function f
must be pure.
def
head
[ar]
(
a :
Array[a, r]
)
: Option[a]
\ r
Returns Some(x)
if x
is the first element of a
.
Returns None
if a
is empty.
def
indexOf
[ar]
(
x :
a
a :
Array[a, r]
)
: Option[Int32]
\ r
with
Eq[a]
Alias for IndexOfLeft
def
indexOfLeft
[ar]
(
a :
a
arr :
Array[a, r]
)
: Option[Int32]
\ r
with
Eq[a]
Optionally returns the position of the first occurrence of a
in arr
searching from left to right.
def
indexOfRight
[ar]
(
a :
a
arr :
Array[a, r]
)
: Option[Int32]
\ r
with
Eq[a]
Optionally returns the position of the first occurrence of a
in arr
searching from right to left.
def
indices
[ra]
(
rc :
Region[r]
a :
a
arr :
Array[a, r]
)
: Array[Int32, r]
\ r
with
Eq[a]
Return the positions of the all the occurrences of a
in arr
.
def
init
[refa]
(
rc :
Region[r]
f :
Int32 -> a \ ef
len :
Int32
)
: Array[a, r]
\ ef + r
Build an array of length len
by applying f
to the successive indices.
def
intercalate
[r1ar]
(
rc1 :
Region[r1]
sep :
Array[a, r]
arrs :
Array[Array[a, r], r]
)
: Array[a, r1]
\ r + r1
Returns the concatenation of the elements in arrs
with the elements of sep
inserted between every two adjacent elements.
def
intersperse
[r1ar]
(
rc1 :
Region[r1]
x :
a
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Returns a
with x
inserted between every two adjacent elements.
def
isEmpty
[ar]
(
a :
Array[a, r]
)
: Bool
\ Pure
Returns true
if the given array a
is empty.
def
isInfixOf
[ar1r2]
(
a1 :
Array[a, r1]
a2 :
Array[a, r2]
)
: Bool
\ r1 + r2
with
Eq[a]
Returns true
if and only if a1
is a infix of a2
.
def
isPrefixOf
[ar1r2]
(
a1 :
Array[a, r1]
a2 :
Array[a, r2]
)
: Bool
\ r1 + r2
with
Eq[a]
Returns true
if and only if a1
is a prefix of a2
.
def
isSuffixOf
[ar1r2]
(
a1 :
Array[a, r1]
a2 :
Array[a, r2]
)
: Bool
\ r1 + r2
with
Eq[a]
Returns true
if and only if a1
is a suffix of a2
.
def
iterator
[r1ar2]
(
rc :
Region[r1]
a :
Array[a, r2]
)
: Iterator[a, r1 + r2, r1]
\ r1
Returns an iterator over a
Modifying a
while using an iterator has undefined behavior and is dangerous.
def
join
[ar]
(
sep :
String
a :
Array[a, r]
)
: String
\ r
with
ToString[a]
Returns the concatenation of the string representation
of each element in a
with sep
inserted between each element.
def
joinWith
[aefr]
(
f :
a -> String \ ef
sep :
String
a :
Array[a, r]
)
: String
\ ef + r
Returns the concatenation of the string representation
of each element in a
according to f
with sep
inserted between each element.
def
last
[ar]
(
a :
Array[a, r]
)
: Option[a]
\ r
Returns Some(x)
if x
is the last element of a
.
Returns None
if a
is empty.
def
length
[ar]
(
a :
Array[a, r]
)
: Int32
\ Pure
Returns the length of the array a
.
def
map
[r1aefbr]
(
rc1 :
Region[r1]
f :
a -> b \ ef
a :
Array[a, r]
)
: Array[b, r1]
\ ef + r + r1
Returns the result of applying f
to every element in a
.
The result is a new array.
def
mapWithIndex
[r1aefbr]
(
rc1 :
Region[r1]
f :
Int32 -> (a -> b \ ef)
a :
Array[a, r]
)
: Array[b, r1]
\ ef + r + r1
Returns the result of applying f
to every element in a
along with that element's index.
That is, the result is of the form: [ f(a[0], 0), f(a[1], 1), ... ]
.
def
maximum
[ar]
(
a :
Array[a, r]
)
: Option[a]
\ r
with
Order[a]
Optionally finds the largest element of a
according to the Order
on a
.
Returns None
if a
is empty.
def
maximumBy
[ar]
(
cmp :
a -> (a -> Comparison)
a :
Array[a, r]
)
: Option[a]
\ r
Optionally finds the largest element of a
according to the given comparator cmp
.
Returns None
if a
is empty.
def
memberOf
[ar]
(
x :
a
a :
Array[a, r]
)
: Bool
\ r
with
Eq[a]
Returns true
if and only if a
contains the element x
.
def
minimum
[ar]
(
a :
Array[a, r]
)
: Option[a]
\ r
with
Order[a]
Optionally finds the smallest element of a
according to the Order
on a
.
Returns None
if a
is empty.
def
minimumBy
[ar]
(
cmp :
a -> (a -> Comparison)
a :
Array[a, r]
)
: Option[a]
\ r
Optionally finds the smallest element of a
according to the given comparator cmp
.
Returns None
if a
is empty.
def
new
[ra]
(
rc :
Region[r]
l :
Int32
)
: Array[a, r]
\ r
Returns a new uninitialized array of length l
in the region r
.
def
nth
[ar]
(
i :
Int32
a :
Array[a, r]
)
: Option[a]
\ r
Optionally returns the element at position i
in the array a
.
def
partition
[r1r2aefr]
(
rc1 :
Region[r1]
rc2 :
Region[r2]
f :
a -> Bool \ ef
a :
Array[a, r]
)
: (Array[a, r1], Array[a, r2])
\ r1 + r2 + ef + r
Returns a pair of arrays (a1, a2)
.
a1
contains all elements of a
that satisfy the predicate f
.
a2
contains all elements of a
that do not satisfy the predicate f
.
def
patch
[r3ar1r2]
(
rc3 :
Region[r3]
i :
Int32
n :
Int32
a :
Array[a, r1]
b :
Array[a, r2]
)
: Array[a, r3]
\ r1 + r2 + r3
Returns b
with the n
elements starting at index i
replaced with the elements of a
.
If any of the indices i, i+1, i+2, ... , i+n-1
are out of range in b
then no patching is done at these indices.
If a
becomes depleted then no further patching is done.
If patching occurs at index i+j
in b
, then the element at index j
in a
is used.
def
patch!
[ar1r2]
(
i :
Int32
n :
Int32
a :
Array[a, r1]
b :
Array[a, r2]
)
: Unit
\ r1 + r2
Update the mutable array b
replacing n
elements starting at index i
with the corresponding elements of array a
.
If any of the indices i, i+1, i+2, ... , i+n-1
are out of range in b
then no patching is done at these indices.
If a
becomes depleted then no further patching is done.
If patching occurs at index i+j
in b
, then the element at index j
in a
is used.
def
put
[ar]
(
x :
a
i :
Int32
a :
Array[a, r]
)
: Unit
\ r
Stores the value x
at position i
in the array a
.
def
range
[r]
(
rc :
Region[r]
b :
Int32
e :
Int32
)
: Array[Int32, r]
\ r
Returns an array of all integers between b
(inclusive) and e
(exclusive).
Returns []
if b >= e
.
def
reduceLeft
[aefr]
(
f :
a -> (a -> a \ ef)
a :
Array[a, r]
)
: Option[a]
\ ef + r
Applies f
to all elements in a
going from left to right until a single value v
is obtained. Returns Some(v)
.
Returns None
if a
is empty.
def
reduceRight
[aefr]
(
f :
a -> (a -> a \ ef)
arr :
Array[a, r]
)
: Option[a]
\ ef + r
Applies f
to all elements in arr
going from right to left until a single value v
is obtained. Returns Some(v)
.
Returns None
if arr
is empty.
def
repeat
[ra]
(
rc :
Region[r]
n :
Int32
x :
a
)
: Array[a, r]
\ r
Returns an array with the element x
repeated n
times.
Returns the empty array if n <= 0
.
def
replace
[r1ar]
(
rc1 :
Region[r1]
from :
{ from = a }
to :
{ to = a }
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
with
Eq[a]
Returns a copy of a
with every occurrence of from
replaced by to
.
def
replace!
[ar]
(
from :
{ from = a }
to :
{ to = a }
a :
Array[a, r]
)
: Unit
\ r
with
Eq[a]
Replace every occurrence of from
by to
in the array a
, mutating it in place.
def
reverse
[r1ar]
(
rc1 :
Region[r1]
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Returns the reverse of a
.
def
reverse!
[ar]
(
arr :
Array[a, r]
)
: Unit
\ r
Reverse the array arr
, mutating it in place.
def
rotateLeft
[r2ar1]
(
rc2 :
Region[r2]
n :
Int32
arr :
Array[a, r1]
)
: Array[a, r2]
\ r1 + r2
Rotate the contents of array arr
by n
steps to the left.
def
rotateRight
[r2ar1]
(
rc2 :
Region[r2]
n :
Int32
arr :
Array[a, r1]
)
: Array[a, r2]
\ r1 + r2
Rotate the contents of array arr
by n
steps to the right.
def
sameElements
[ar1r2]
(
a :
Array[a, r1]
b :
Array[a, r2]
)
: Bool
\ r1 + r2
with
Eq[a]
Returns true
if arrays a
and b
have the same elements in the same order, i.e. are structurally equal.
def
scan
[rbaef]
(
rc :
Region[r]
f :
b -> (a -> b \ ef)
s :
b
arr :
Array[a, r]
)
: Array[b, r]
\ ef + r
Alias for scanLeft
.
def
scanLeft
[rbaef]
(
rc :
Region[r]
f :
b -> (a -> b \ ef)
s :
b
arr :
Array[a, r]
)
: Array[b, r]
\ ef + r
Accumulates the result of applying f
to arr
going left to right.
That is, the result is of the form: [s , f(s, x1), f(f(s, x1), x2), ...]
.
def
scanRight
[rabef]
(
rc :
Region[r]
f :
a -> (b -> b \ ef)
s :
b
a :
Array[a, r]
)
: Array[b, r]
\ ef + r
Accumulates the result of applying f
to xs
going right to left.
That is, the result is of the form: [..., f(xn-1, f(xn, s)), f(xn, s), s]
.
def
shuffle
[ar]
(
rnd :
Random
a :
Array[a, r]
)
: Unit
\ IO
Shuffles a
using the Fisher–Yates shuffle.
def
slice
[r1ar]
(
rc1 :
Region[r1]
start :
{ start = Int32 }
end :
{ end = Int32 }
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Returns a fresh array with the elements from the array a
from index start
(inclusive) until index end
(exclusive).
def
sort
[r1ar]
(
rc1 :
Region[r1]
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
with
Order[a]
Returns a sorted copy of array a
, where the elements are ordered from low to high according to
their Order
instance.
The sort is not stable, i.e., equal elements may appear in a different order than in the input a
.
The sort implementation is a Quicksort.
def
sort!
[ar]
(
a :
Array[a, r]
)
: Unit
\ r
with
Order[a]
Sort array a
so that elements are ordered from low to high according to their Order
instance.
The array is mutated in-place.
The sort is not stable, i.e., equal elements may appear in a different order than in the input a
.
The sort implementation is a Quicksort.
def
sortBy
[r1abr]
(
rc1 :
Region[r1]
f :
a -> b
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
with
Order[b]
Returns a sorted copy of array a
, where the elements are ordered from low to high according to
the Order
instance for the values obtained by applying f
to each element.
The sort is not stable, i.e., equal elements may appear in a different order than in the input a
.
The sort implementation is a Quicksort.
def
sortBy!
[abr]
(
f :
a -> b
a :
Array[a, r]
)
: Unit
\ r
with
Order[b]
Sort array a
so that elements are ordered from low to high according to the Order
instance for
the values obtained by applying f
to each element. The array is mutated in-place.
The sort is not stable, i.e., equal elements may appear in a different order than in the input a
.
The sort implementation is a Quicksort.
def
sortWith
[r1ar]
(
rc1 :
Region[r1]
cmp :
a -> (a -> Comparison)
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Returns a sorted copy of array a
, where the elements are ordered from low to high according to
the comparison function cmp
.
The sort is not stable, i.e., equal elements may appear in a different order than in the input a
.
The sort implementation is a Quicksort.
def
sortWith!
[ar]
(
cmp :
a -> (a -> Comparison)
a :
Array[a, r]
)
: Unit
\ r
Sort array a
so that elements are ordered from low to high according to the comparison function cmp
.
The array is mutated in-place.
The sort is not stable, i.e., equal elements may appear in a different order than in the input a
.
The sort implementation is a Quicksort.
def
sortWithin!
[ar]
(
cmp :
a -> (a -> Comparison)
lo :
Int32
hi :
Int32
a :
Array[a, r]
)
: Unit
\ r
Sort array a
between the indices lo
and hi
(both inclusive) so that elements in that range are ordered
from low to high according to the comparison function cmp
. The array is mutated in-place where elements
outside the specified range are not changed. If lo >= hi
, this does nothing.
The sort is not stable, i.e., equal elements may appear in a different order than in the input a
.
The sort implementation is a Quicksort.
def
span
[r1r2aefr]
(
rc1 :
Region[r1]
rc2 :
Region[r2]
f :
a -> Bool \ ef
a :
Array[a, r]
)
: (Array[a, r1], Array[a, r2])
\ r1 + r2 + ef + r
Returns a pair of arrays (a1, a2)
.
a1
is the longest prefix of a
that satisfies the predicate f
.
a2
is the remainder of a
.
def
sum
[r]
(
a :
Array[Int32, r]
)
: Int32
\ r
Returns the sum of all elements in the array a
.
def
sumWith
[aefr]
(
f :
a -> Int32 \ ef
a :
Array[a, r]
)
: Int32
\ ef + r
Returns the sum of all elements in the array a
according to the function f
.
def
swap!
[ar]
(
i :
Int32
j :
Int32
a :
Array[a, r]
)
: Unit
\ r
Swap the elements at i
and j
(helper for sorting).
Precondition: i
and j
are within bounds.
def
take
[r1ar]
(
rc1 :
Region[r1]
n :
Int32
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Alias for takeLeft
.
def
takeLeft
[r1ar]
(
rc1 :
Region[r1]
n :
Int32
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Returns a fresh array taking first n
elements of a
.
Returns a
if n > length(xs)
.
def
takeRight
[r1ar]
(
rc1 :
Region[r1]
n :
Int32
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Returns a fresh array taking last n
elements of a
.
Returns a
if n > length(xs)
.
def
takeWhile
[r1aefr]
(
rc1 :
Region[r1]
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Array[a, r1]
\ ef + r + r1
Alias for takeWhileLeft
.
def
takeWhileLeft
[r1aefr]
(
rc1 :
Region[r1]
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Array[a, r1]
\ ef + r + r1
Returns the longest prefix of a
that satisfies the predicate f
.
def
takeWhileRight
[r1aefr]
(
rc1 :
Region[r1]
f :
a -> Bool \ ef
a :
Array[a, r]
)
: Array[a, r1]
\ ef + r + r1
Returns the longest suffix of a
that satisfies the predicate f
.
def
toChain
[ar]
(
arr :
Array[a, r]
)
: Chain[a]
\ r
Returns the array arr
as a chain.
def
toDelayList
[ar]
(
a :
Array[a, r]
)
: DelayList[a]
\ r
Returns the array a
as a DelayList
.
def
toList
[ar]
(
a :
Array[a, r]
)
: List[a]
\ r
Returns the array a
as a list.
def
toMap
[abr]
(
a :
Array[(a, b), r]
)
: Map[a, b]
\ r
with
Order[a]
Returns the association list xs
as a map.
If xs
contains multiple mappings with the same key, toMap
does not
make any guarantees about which mapping will be in the resulting map.
def
toMutDeque
[r1ar2]
(
rc1 :
Region[r1]
a :
Array[a, r2]
)
: MutDeque[a, r1]
\ r2 + r1
Returns a
as a MutDeque.
def
toMutList
[r1ar2]
(
rc1 :
Region[r1]
a :
Array[a, r2]
)
: MutList[a, r1]
\ r2 + r1
Returns the array a
as a MutList.
def
toNec
[ar]
(
arr :
Array[a, r]
)
: Option[Nec[a]]
\ r
Optionally returns the array arr
as a non-empty chain.
If arr
is empty return None
, otherwise return the Nec wrapped in Some
.
def
toNel
[ar]
(
arr :
Array[a, r]
)
: Option[Nel[a]]
\ r
Optionally returns the array arr
as a non-empty list.
If arr
is empty return None
, otherwise return the Nel wrapped in Some
.
def
toSet
[ar]
(
a :
Array[a, r]
)
: Set[a]
\ r
with
Order[a]
Returns the array a
as a set.
def
toString
[ar]
(
a :
Array[a, r]
)
: String
\ r
with
ToString[a]
Returns a string representation of the given array a
.
def
toVector
[ar]
(
a :
Array[a, r]
)
: Vector[a]
\ r
Returns a
as a Vector.
def
transform!
[aefr]
(
f :
a -> a \ ef
arr :
Array[a, r]
)
: Unit
\ ef + r
Apply f
to every element in array arr
. Array arr
is mutated.
def
transformWithIndex!
[aefr]
(
f :
Int32 -> (a -> a \ ef)
arr :
Array[a, r]
)
: Unit
\ ef + r
Apply f
to every element in array a
along with that element's index. Array a
is mutated.
def
transpose
[r3ar1r2]
(
rc3 :
Region[r3]
a :
Array[Array[a, r1], r2]
)
: Array[Array[a, r3], r3]
\ r1 + r2 + r3
Returns the transpose of a
.
Returns a
if the dimensions of the elements of a
are mismatched.
def
unzip
[r1r2abr3]
(
rc1 :
Region[r1]
rc2 :
Region[r2]
a :
Array[(a, b), r3]
)
: (Array[a, r1], Array[b, r2])
\ r1 + r2 + r3
Returns a pair of arrays, the first containing all first components in a
and the second containing all second components in a
.
def
update
[r1ar]
(
rc1 :
Region[r1]
i :
Int32
x :
a
a :
Array[a, r]
)
: Array[a, r1]
\ r + r1
Returns a copy of a
with the element at index i
replaced by x
.
Returns a shallow copy of a
if i < 0
or i > length(xs)-1
.
def
updateSequence
[r3ar1r2]
(
rc3 :
Region[r3]
i :
Int32
sub :
Array[a, r1]
a :
Array[a, r2]
)
: Array[a, r3]
\ r1 + r2 + r3
Returns a copy of a
with the elements starting at index i
replaced by sub
.
def
updateSequence!
[ar1r2]
(
i :
Int32
sub :
Array[a, r1]
a :
Array[a, r2]
)
: Unit
\ r1 + r2
Update the mutable array a
with the elements starting at index i
replaced by sub
.
def
zip
[r3ar1br2]
(
rc3 :
Region[r3]
a :
Array[a, r1]
b :
Array[b, r2]
)
: Array[(a, b), r3]
\ r1 + r2 + r3
Returns an array where the element at index i
is (x, y)
where
x
is the element at index i
in a
and y
is the element at index i
in b
.
If either a
or b
becomes depleted, then no further elements are added to the resulting array.
def
zipWith
[r3abefcr1r2]
(
rc3 :
Region[r3]
f :
a -> (b -> c \ ef)
a :
Array[a, r1]
b :
Array[b, r2]
)
: Array[c, r3]
\ r3 + ef + r1 + r2
Returns an array where the element at index i
is f(x, y)
where
x
is the element at index i
in a
and y
is the element at index i
in b
.
If either a
or b
becomes depleted, then no further elements are added to the resulting array.