Array
Definitions
def append(rc3: Region[r3], a: Array[a, r1], b: Array[a, r2]): Array[a, r3] \ r1 + r2 + r3
SourceReturn a new array, appending the elements b
to elements of a
.
Compares a
and b
lexicographically.
def copyOfRange(_: Region[r2], b: Int32, e: Int32, a: Array[a, r1]): Array[a, r2] \ r1 + r2
SourceCopies the range between b
(inclusive) and e
(exclusive) of a into an empty array.
A valid range has the following properties:
- 0 <= b
<= length(a)
.
- e
>= b
.
If the range is valid and greater than the length of a
, the resulting array with have the length of the range
and include the specified range of a
.
def count(f: a -> Bool \ ef, a: Array[a, r]): Int32 \ ef + r
SourceReturns the number of elements in a
that satisfy the predicate f
.
def drop(rc1: Region[r1], n: Int32, a: Array[a, r]): Array[a, r1] \ r + r1
SourceAlias for dropLeft
.
def dropLeft(rc1: Region[r1], n: Int32, a: Array[a, r]): Array[a, r1] \ r + r1
SourceReturns a copy of array a
, dropping the first n
elements.
Returns []
if n > length(a)
.
def dropRight(rc1: Region[r1], n: Int32, a: Array[a, r]): Array[a, r1] \ r + r1
SourceReturns a copy of array a
, dropping the last n
elements.
Returns []
if n > length(a)
.
def dropWhile(rc1: Region[r1], f: a -> Bool \ ef, a: Array[a, r]): Array[a, r1] \ ef + r + r1
SourceAlias for dropWhileLeft
.
def dropWhileLeft(rc1: Region[r1], f: a -> Bool \ ef, a: Array[a, r]): Array[a, r1] \ ef + r + r1
SourceReturns copy of array a
without the longest prefix that satisfies the predicate f
.
def dropWhileRight(rc1: Region[r1], f: a -> Bool \ ef, a: Array[a, r]): Array[a, r1] \ ef + r + r1
SourceReturns copy of array a
without the longest suffix that satisfies the predicate f
.
def empty(rc: Region[r], l: Int32): Array[a, r] \ r
SourceReturns a new uninitialized array of length l
in the region r
.
def enumerator(rc: Region[r1], a: Array[a, r2]): Iterator[(Int32, a), r1 + r2, r1] \ r1 + r2
SourceReturns 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(f: a -> Bool \ ef, arr: Array[a, r]): Bool \ ef + r
SourceReturns true
if and only if at least one element in arr
satisfies the predicate f
.
Returns false
if arr
is empty.
def filter(rc1: Region[r1], f: a -> Bool \ ef, arr: Array[a, r]): Array[a, r1] \ ef + r + r1
SourceReturns an array of every element in arr
that satisfies the predicate f
.
def filterMap(rc1: Region[r1], f: a -> Option[b] \ ef, a: Array[a, r]): Array[b, r1] \ ef + r + r1
SourceCollects the results of applying the partial function f
to every element in a
.
def find(f: a -> Bool \ ef, arr: Array[a, r]): Option[a] \ ef + r
SourceAlias for findLeft
.
def findIndexOf(f: a -> Bool \ ef, a: Array[a, r]): Option[Int32] \ ef + r
SourceAlias for findIndexOfLeft
.
def findIndexOfLeft(f: a -> Bool \ ef, a: Array[a, r]): Option[Int32] \ ef + r
SourceOptionally returns the position of the first element in x
satisfying f
.
def findIndexOfRight(f: a -> Bool \ ef, a: Array[a, r]): Option[Int32] \ ef + r
SourceOptionally returns the position of the first element in a
satisfying f
searching from right to left.
def findIndices(rc2: Region[r2], f: a -> Bool \ ef, a: Array[a, r1]): Array[Int32, r2] \ ef + r1 + r2
SourceReturns the positions of the all the elements in a
satisfying f
.
def findLeft(f: a -> Bool \ ef, arr: Array[a, r]): Option[a] \ ef + r
SourceOptionally returns the first element of a
that satisfies the predicate f
when searching from left to right.
def findMap(f: a -> Option[b] \ ef, a: Array[a, r]): Option[b] \ ef + r
SourceReturns 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(f: a -> Bool \ ef, arr: Array[a, r]): Option[a] \ ef + r
SourceOptionally returns the first element of xs
that satisfies the predicate f
when searching from right to left.
def flatMap(rc1: Region[r1], f: a -> Array[b, r1] \ ef, a: Array[a, r]): Array[b, r1] \ ef + r + r1
SourceReturns the result of applying f
to every element in a
and concatenating the results.
def flatten(rc1: Region[r1], arrs: Array[Array[a, r], r]): Array[a, r1] \ r + r1
SourceReturns the concatenation of the arrays of in the array arrs
.
Returns the result of applying combine
to all the elements in a
, using empty
as the initial value.
def fold2(f: c -> (a -> (b -> c \ ef)), c: c, a: Array[a, r1], b: Array[b, r2]): c \ ef + r1 + r2
SourceAlias for foldLeft2
.
def foldLeft(f: b -> (a -> b \ ef), s: b, arr: Array[a, r]): b \ ef + r
SourceApplies 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(f: c -> (a -> (b -> c \ ef)), c: c, a: Array[a, r1], b: Array[b, r2]): c \ ef + r1 + r2
SourceAccumulates 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.
Returns the result of mapping each element and combining the results.
def foldRight(f: a -> (b -> b \ ef), s: b, arr: Array[a, r]): b \ ef + r
SourceApplies 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(f: a -> (b -> (c -> c \ ef)), c: c, a: Array[a, r1], b: Array[b, r2]): c \ ef + r1 + r2
SourceAccumulates 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(f: a -> ((Unit -> b \ ef + r) -> b \ ef + r), z: b, arr: Array[a, r]): b \ ef + r
SourceApplies 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(f: a -> Bool \ ef, arr: Array[a, r]): Bool \ ef + r
SourceReturns true
if and only if all elements in arr
satisfy the predicate f
.
Returns true
if arr
is empty.
def forEach(f: a -> Unit \ ef, a: Array[a, r]): Unit \ ef + r
SourceApply the effectful function f
to all the elements in the array a
.
def forEachWithIndex(f: Int32 -> (a -> Unit \ ef), a: Array[a, r]): Unit \ ef + r
SourceApply the effectful function f
to all the elements in the array a
.
def get(i: Int32, a: Array[a, r]): a \ r
SourceRetrieves the value at position i
in the array a
.
def groupBy(rc1: Region[r1], f: a -> (a -> Bool), a: Array[a, r2]): Array[Array[a, r1], r1] \ r2 + r1
SourcePartitions 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(a: Array[a, r]): Option[a] \ r
SourceReturns Some(x)
if x
is the first element of a
.
Returns None
if a
is empty.
Optionally returns the position of the first occurrence of a
in arr
searching from left to right.
Optionally returns the position of the first occurrence of a
in arr
searching from right to left.
Return the positions of the all the occurrences of a
in arr
.
def init(rc: Region[r], f: Int32 -> a \ ef, len: Int32): Array[a, r] \ ef + r
SourceBuild an array of length len
by applying f
to the successive indices.
def intercalate(rc1: Region[r1], sep: Array[a, r], arrs: Array[Array[a, r], r]): Array[a, r1] \ r + r1
SourceReturns the concatenation of the elements in arrs
with the elements of sep
inserted between every two adjacent elements.
def intersperse(rc1: Region[r1], x: a, a: Array[a, r]): Array[a, r1] \ r + r1
SourceReturns a
with x
inserted between every two adjacent elements.
def isEmpty(a: Array[a, r]): Bool \ r
SourceReturns true
if the given array a
is empty.
Returns true
if and only if a1
is a infix of a2
.
Returns true
if and only if a1
is a prefix of a2
.
Returns true
if and only if a1
is a suffix of a2
.
def iterator(rc: Region[r1], a: Array[a, r2]): Iterator[a, r1 + r2, r1] \ r1 + r2
SourceReturns an iterator over a
Modifying a
while using an iterator has undefined behavior and is dangerous.
Returns the concatenation of the string representation
of each element in a
with sep
inserted between each element.
def joinWith(f: a -> String \ ef, sep: String, a: Array[a, r]): String \ ef + r
SourceReturns the concatenation of the string representation
of each element in a
according to f
with sep
inserted between each element.
def last(a: Array[a, r]): Option[a] \ r
SourceReturns Some(x)
if x
is the last element of a
.
Returns None
if a
is empty.
def length(a: Array[a, r]): Int32 \ r
SourceReturns the number of elements in the array a
.
def map(rc1: Region[r1], f: a -> b \ ef, a: Array[a, r]): Array[b, r1] \ ef + r + r1
SourceReturns the result of applying f
to every element in a
.
The result is an empty array.
def mapWithIndex(rc1: Region[r1], f: Int32 -> (a -> b \ ef), a: Array[a, r]): Array[b, r1] \ ef + r + r1
SourceReturns 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), ... ]
.
Optionally finds the largest element of a
according to the Order
on a
.
Returns None
if a
is empty.
def maximumBy(cmp: a -> (a -> Comparison), a: Array[a, r]): Option[a] \ r
SourceOptionally finds the largest element of a
according to the given comparator cmp
.
Returns None
if a
is empty.
Returns true
if and only if a
contains the element x
.
Optionally finds the smallest element of a
according to the Order
on a
.
Returns None
if a
is empty.
def minimumBy(cmp: a -> (a -> Comparison), a: Array[a, r]): Option[a] \ r
SourceOptionally finds the smallest element of a
according to the given comparator cmp
.
Returns None
if a
is empty.
def nonEmpty(a: Array[a, r]): Bool \ r
SourceReturns true
if the given array a
is non-empty.
def nth(i: Int32, a: Array[a, r]): Option[a] \ r
SourceOptionally returns the element at position i
in the array a
.
def partition(rc1: Region[r1], rc2: Region[r2], f: a -> Bool \ ef, a: Array[a, r]): (Array[a, r1], Array[a, r2]) \ ef + r + r1 + r2
SourceReturns 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(rc3: Region[r3], i: Int32, n: Int32, a: Array[a, r1], b: Array[a, r2]): Array[a, r3] \ r1 + r2 + r3
SourceReturns 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!(i: Int32, n: Int32, a: Array[a, r1], b: Array[a, r2]): Unit \ r1 + r2
SourceUpdate 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(x: a, i: Int32, a: Array[a, r]): Unit \ r
SourceStores the value x
at position i
in the array a
.
def range(rc: Region[r], b: Int32, e: Int32): Array[Int32, r] \ r
SourceReturns an array of all integers between b
(inclusive) and e
(exclusive).
Returns []
if b >= e
.
def reduceLeft(f: a -> (a -> a \ ef), a: Array[a, r]): Option[a] \ ef + r
SourceApplies 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(f: a -> (a -> a \ ef), arr: Array[a, r]): Option[a] \ ef + r
SourceApplies 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(rc: Region[r], n: Int32, x: a): Array[a, r] \ r
SourceReturns an array with the element x
repeated n
times.
Returns the empty array if n <= 0
.
def replace(rc1: Region[r1], src: { src = a }, dst: { dst = a }, a: Array[a, r]): Array[a, r1] \ r + r1 with Eq[a]
SourceReturns a copy of a
with every occurrence of src
replaced by dst
.
Replace every occurrence of src
by dst
in the array a
, mutating it in place.
def reverse(rc1: Region[r1], a: Array[a, r]): Array[a, r1] \ r + r1
SourceReturns the reverse of a
.
def reverse!(arr: Array[a, r]): Unit \ r
SourceReverse the array arr
, mutating it in place.
def rotateLeft(rc2: Region[r2], n: Int32, arr: Array[a, r1]): Array[a, r2] \ r1 + r2
SourceRotate the contents of array arr
by n
steps to the left.
def rotateRight(rc2: Region[r2], n: Int32, arr: Array[a, r1]): Array[a, r2] \ r1 + r2
SourceRotate the contents of array arr
by n
steps to the right.
Returns true
if arrays a
and b
have the same elements in the same order, i.e. are structurally equal.
def scan(rc: Region[r], f: b -> (a -> b \ ef), s: b, arr: Array[a, r]): Array[b, r] \ ef + r
SourceAlias for scanLeft
.
def scanLeft(rc: Region[r], f: b -> (a -> b \ ef), s: b, arr: Array[a, r]): Array[b, r] \ ef + r
SourceAccumulates 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(rc: Region[r], f: a -> (b -> b \ ef), s: b, a: Array[a, r]): Array[b, r] \ ef + r
SourceAccumulates 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(a: Array[a, r]): Unit \ r + NonDet
SourceShuffles a
using the Fisher–Yates shuffle.
def size(a: Array[a, r]): Int32 \ r
SourceReturns the number of elements in the array a
.
def slice(rc1: Region[r1], start: { start = Int32 }, end: { end = Int32 }, a: Array[a, r]): Array[a, r1] \ r + r1
SourceReturns a fresh array with the elements from the array a
from index start
(inclusive) until index end
(exclusive).
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.
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.
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.
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(rc1: Region[r1], cmp: a -> (a -> Comparison), a: Array[a, r]): Array[a, r1] \ r + r1
SourceReturns 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!(cmp: a -> (a -> Comparison), a: Array[a, r]): Unit \ r
SourceSort 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!(cmp: a -> (a -> Comparison), lo: Int32, hi: Int32, a: Array[a, r]): Unit \ r
SourceSort 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(rc1: Region[r1], rc2: Region[r2], f: a -> Bool \ ef, a: Array[a, r]): (Array[a, r1], Array[a, r2]) \ ef + r + r1 + r2
SourceReturns 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(a: Array[Int32, r]): Int32 \ r
SourceReturns the sum of all elements in the array a
.
def sumWith(f: a -> Int32 \ ef, a: Array[a, r]): Int32 \ ef + r
SourceReturns the sum of all elements in the array a
according to the function f
.
def swap!(i: Int32, j: Int32, a: Array[a, r]): Unit \ r
SourceSwap the elements at i
and j
(helper for sorting).
Precondition: i
and j
are within bounds.
def take(rc1: Region[r1], n: Int32, a: Array[a, r]): Array[a, r1] \ r + r1
SourceAlias for takeLeft
.
def takeLeft(rc1: Region[r1], n: Int32, a: Array[a, r]): Array[a, r1] \ r + r1
SourceReturns a fresh array taking first n
elements of a
.
Returns a
if n > length(xs)
.
def takeRight(rc1: Region[r1], n: Int32, a: Array[a, r]): Array[a, r1] \ r + r1
SourceReturns a fresh array taking last n
elements of a
.
Returns a
if n > length(xs)
.
def takeWhile(rc1: Region[r1], f: a -> Bool \ ef, a: Array[a, r]): Array[a, r1] \ ef + r + r1
SourceAlias for takeWhileLeft
.
def takeWhileLeft(rc1: Region[r1], f: a -> Bool \ ef, a: Array[a, r]): Array[a, r1] \ ef + r + r1
SourceReturns the longest prefix of a
that satisfies the predicate f
.
def takeWhileRight(rc1: Region[r1], f: a -> Bool \ ef, a: Array[a, r]): Array[a, r1] \ ef + r + r1
SourceReturns the longest suffix of a
that satisfies the predicate f
.
def toChain(arr: Array[a, r]): Chain[a] \ r
SourceReturns the array arr
as a chain.
def toDelayList(a: Array[a, r]): DelayList[a] \ r
SourceReturns the array a
as a DelayList
.
def toList(a: Array[a, r]): List[a] \ r
SourceReturns the array a
as a list.
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(rc1: Region[r1], a: Array[a, r2]): MutDeque[a, r1] \ r2 + r1
SourceReturns a
as a MutDeque.
def toMutList(rc1: Region[r1], a: Array[a, r2]): MutList[a, r1] \ r2 + r1
SourceReturns the array a
as a MutList.
def toNec(arr: Array[a, r]): Option[Nec[a]] \ r
SourceOptionally returns the array arr
as a non-empty chain.
If arr
is empty return None
, otherwise return the Nec wrapped in Some
.
def toNel(arr: Array[a, r]): Option[Nel[a]] \ r
SourceOptionally returns the array arr
as a non-empty list.
If arr
is empty return None
, otherwise return the Nel wrapped in Some
.
Returns a string representation of the given array a
.
def toVector(a: Array[a, r]): Vector[a] \ r
SourceReturns a
as a Vector.
def transform!(f: a -> a \ ef, arr: Array[a, r]): Unit \ ef + r
SourceApply f
to every element in array arr
. Array arr
is mutated.
def transformWithIndex!(f: Int32 -> (a -> a \ ef), arr: Array[a, r]): Unit \ ef + r
SourceApply f
to every element in array a
along with that element's index. Array a
is mutated.
def transpose(rc3: Region[r3], a: Array[Array[a, r1], r2]): Array[Array[a, r3], r3] \ r1 + r2 + r3
SourceReturns the transpose of a
.
Returns a
if the dimensions of the elements of a
are mismatched.
def unzip(rc1: Region[r1], rc2: Region[r2], a: Array[(a, b), r3]): (Array[a, r1], Array[b, r2]) \ r1 + r2 + r3
SourceReturns a pair of arrays, the first containing all first components in a
and the second containing all second components in a
.
def update(rc1: Region[r1], i: Int32, x: a, a: Array[a, r]): Array[a, r1] \ r + r1
SourceReturns 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(rc3: Region[r3], i: Int32, sub: Array[a, r1], a: Array[a, r2]): Array[a, r3] \ r1 + r2 + r3
SourceReturns a copy of a
with the elements starting at index i
replaced by sub
.
def updateSequence!(i: Int32, sub: Array[a, r1], a: Array[a, r2]): Unit \ r1 + r2
SourceUpdate the mutable array a
with the elements starting at index i
replaced by sub
.
def zip(rc3: Region[r3], a: Array[a, r1], b: Array[b, r2]): Array[(a, b), r3] \ r1 + r2 + r3
SourceReturns 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(rc3: Region[r3], f: a -> (b -> c \ ef), a: Array[a, r1], b: Array[b, r2]): Array[c, r3] \ ef + r1 + r2 + r3
SourceReturns 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.