Vector
Definitions
def
ap
[aefb]
(
f :
Vector[a -> b \ ef]
v :
Vector[a]
)
: Vector[b]
\ ef
Apply every function from f
to every argument from v
and return a list with all results.
For f = f1, f2, ...
and x = x1, x2, ...
the results appear in the order
f1(x1), f1(x2), ..., f2(x1), f2(x2), ...
.
def
append
[a]
(
v1 :
Vector[a]
v2 :
Vector[a]
)
: Vector[a]
\ Pure
Return a new vector, appending the elements v2
after elements of v1
.
def
compare
[a]
(
a :
Vector[a]
b :
Vector[a]
)
: Comparison
\ Pure
with
Order[a]
Compares a
and b
lexicographically.
def
count
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Int32
\ ef
Returns the number of elements in v
that satisfy the predicate f
.
def
drop
[a]
(
n :
Int32
v :
Vector[a]
)
: Vector[a]
\ Pure
Alias for dropLeft
.
def
dropLeft
[a]
(
n :
Int32
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns a copy of vector v
, dropping the first n
elements.
Returns an empty vector if n > length(v)
.
def
dropRight
[a]
(
n :
Int32
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns a copy of vector v
, dropping the last n
elements.
Returns an empty vector if n > length(v)
.
def
dropWhile
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Vector[a]
\ ef
Alias for dropWhileLeft
.
def
dropWhileLeft
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Vector[a]
\ ef
Returns copy of vector v
without the longest prefix that satisfies the predicate f
.
def
dropWhileRight
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Vector[a]
\ ef
Returns copy of vector v
without the longest suffix that satisfies the predicate f
.
def
empty
[a]
: Vector[a]
\ Pure
Returns an empty (length zero) vector.
def
enumerator
[ra]
(
rc :
Region[r]
v :
Vector[a]
)
: Iterator[(Int32, a), r, r]
\ r
Returns an iterator over v
zipped with the indices of the elements.
Modifying a
while using an iterator has undefined behavior and is dangerous.
def
equals
[a]
(
a :
Vector[a]
b :
Vector[a]
)
: Bool
\ Pure
with
Eq[a]
Returns true
if arrays a
and b
have the same elements in the same order, i.e. are structurally equal.
def
exists
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Bool
\ ef
Returns true
if and only if at least one element in v
satisfies the predicate f
.
Returns false
if v
is empty.
def
filter
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Vector[a]
\ ef
Returns an array of every element in arr
that satisfies the predicate f
.
def
filterMap
[aefb]
(
f :
a -> Option[b] \ ef
v :
Vector[a]
)
: Vector[b]
\ ef
Collects the successful results of applying the partial function f
to every element in v
.
def
find
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Option[a]
\ ef
Alias for findLeft
.
def
findIndexOf
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Option[Int32]
\ ef
Alias for findIndexOfLeft
.
def
findIndexOfLeft
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Option[Int32]
\ ef
Optionally returns the position of the first element in v
satisfying f
.
def
findIndexOfRight
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Option[Int32]
\ ef
Optionally returns the position of the first element in v
satisfying f
searching from right to left.
def
findIndices
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Vector[Int32]
\ ef
Returns the positions of the all the elements in v
satisfying f
.
def
findLeft
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Option[a]
\ ef
Optionally returns the first element of v
that satisfies the predicate f
when searching from left to right.
def
findMap
[aefb]
(
f :
a -> Option[b] \ ef
v :
Vector[a]
)
: Option[b]
\ ef
Returns the first non-None result of applying the partial function f
to each element of v
.
Returns None
if every element of xs
is None
.
def
findRight
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Option[a]
\ ef
Optionally returns the first element of v
that satisfies the predicate f
when searching from right to left.
def
flatMap
[aefb]
(
f :
a -> Vector[b] \ ef
v :
Vector[a]
)
: Vector[b]
\ ef
Returns the result of applying f
to every element in v
and concatenating the results.
def
flatten
[a]
(
vs :
Vector[Vector[a]]
)
: Vector[a]
\ Pure
Returns the concatenation of all the vectors in the vector vs
.
def
fold
[a]
(
v :
Vector[a]
)
: a
\ Pure
with
Monoid[a]
Returns the result of applying combine
to all the elements in v
, using empty
as the initial value.
def
fold2
[cabef]
(
f :
c -> (a -> (b -> c \ ef))
c :
c
a :
Vector[a]
b :
Vector[b]
)
: c
\ ef
Alias for foldLeft2
.
def
foldLeft
[baef]
(
f :
b -> (a -> b \ ef)
s :
b
v :
Vector[a]
)
: b
\ ef
Applies f
to a start value s
and all elements in v
going from left to right.
That is, the result is of the form: f(...f(f(s, a[0]), a[1])..., xn)
.
def
foldLeft2
[cabef]
(
f :
c -> (a -> (b -> c \ ef))
c :
c
a :
Vector[a]
b :
Vector[b]
)
: c
\ ef
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
[aefb]
(
f :
a -> b \ ef
v :
Vector[a]
)
: b
\ ef
with
Monoid[b]
Returns the result of mapping each element and combining the results.
def
foldRight
[abef]
(
f :
a -> (b -> b \ ef)
s :
b
v :
Vector[a]
)
: b
\ ef
Applies f
to a start value s
and all elements in v
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
[abcef]
(
f :
a -> (b -> (c -> c \ ef))
c :
c
a :
Vector[a]
b :
Vector[b]
)
: c
\ ef
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
[aefb]
(
f :
a -> ((Unit -> b \ ef) -> b \ ef)
z :
b
v :
Vector[a]
)
: b
\ ef
Applies f
to a start value z
and all elements in v
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
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Bool
\ ef
Returns true
if and only if all elements in v
satisfy the predicate f
.
Returns true
if v
is empty.
def
forEach
[aef]
(
f :
a -> Unit \ ef
v :
Vector[a]
)
: Unit
\ ef
Apply the effectful function f
to all the elements in the vector v
.
def
forEachWithIndex
[aef]
(
f :
Int32 -> (a -> Unit \ ef)
v :
Vector[a]
)
: Unit
\ ef
Apply the effectful function f
to all the elements in the vector v
.
def
get
[a]
(
i :
Int32
v :
Vector[a]
)
: a
\ Pure
Retrieves the value at position i
in the vector v
.
def
groupBy
[a]
(
f :
a -> (a -> Bool)
v :
Vector[a]
)
: Vector[Vector[a]]
\ Pure
Partitions v
into subvectors such that for any two elements x
and y
in a subvector, f(x, y)
is true.
A subvector is created by iterating through the remaining elements of v
from left to right and adding an
element to the subvector if and only if doing so creates no conflicts with the elements already in the subvector.
The function f
must be pure.
def
head
[a]
(
v :
Vector[a]
)
: Option[a]
\ Pure
Returns Some(x)
if x
is the first element of v
.
Returns None
if v
is empty.
def
indexOf
[a]
(
x :
a
v :
Vector[a]
)
: Option[Int32]
\ Pure
with
Eq[a]
Alias for IndexOfLeft
def
indexOfLeft
[a]
(
a :
a
v :
Vector[a]
)
: Option[Int32]
\ Pure
with
Eq[a]
Optionally returns the position of the first occurrence of a
in v
searching from left to right.
def
indexOfRight
[a]
(
a :
a
v :
Vector[a]
)
: Option[Int32]
\ Pure
with
Eq[a]
Optionally returns the position of the first occurrence of a
in v
searching from right to left.
def
indices
[a]
(
a :
a
v :
Vector[a]
)
: Vector[Int32]
\ Pure
with
Eq[a]
Return the positions of the all the occurrences of a
in v
.
def
init
[efa]
(
f :
Int32 -> a \ ef
len :
Int32
)
: Vector[a]
\ ef
Build an vector of length len
by applying f
to the successive indices.
def
intercalate
[a]
(
sep :
Vector[a]
vs :
Vector[Vector[a]]
)
: Vector[a]
\ Pure
Returns the concatenation of the elements in vs
with the elements
of sep
inserted between every two adjacent elements.
def
intersperse
[a]
(
sep :
a
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns a copy of v
with sep
inserted between every two adjacent elements.
def
isEmpty
[a]
(
v :
Vector[a]
)
: Bool
\ Pure
Returns true
if the given vector v
is empty.
def
isInfixOf
[a]
(
a :
Vector[a]
b :
Vector[a]
)
: Bool
\ Pure
with
Eq[a]
Returns true
if and only if a
is a infix of b
.
def
isPrefixOf
[a]
(
a :
Vector[a]
b :
Vector[a]
)
: Bool
\ Pure
with
Eq[a]
Returns true
if and only if a
is a prefix of b
.
def
isSuffixOf
[a]
(
a :
Vector[a]
b :
Vector[a]
)
: Bool
\ Pure
with
Eq[a]
Returns true
if and only if a
is a suffix of b
.
def
iterator
[ra]
(
rc :
Region[r]
v :
Vector[a]
)
: Iterator[a, r, r]
\ r
Returns an iterator over v
def
join
[a]
(
sep :
String
v :
Vector[a]
)
: String
\ Pure
with
ToString[a]
Returns the concatenation of the string representation
of each element in v
with sep
inserted between each element.
def
joinWith
[aef]
(
f :
a -> String \ ef
sep :
String
v :
Vector[a]
)
: String
\ ef
Returns the concatenation of the string representation
of each element in v
according to f
with sep
inserted between each element.
def
last
[a]
(
v :
Vector[a]
)
: Option[a]
\ Pure
Returns Some(x)
if x
is the last element of v
.
Returns None
if v
is empty.
def
length
[a]
(
v :
Vector[a]
)
: Int32
\ Pure
Returns the length of the vector v
.
def
map
[aefb]
(
f :
a -> b \ ef
v :
Vector[a]
)
: Vector[b]
\ ef
Returns the result of applying f
to every element in v
.
The result is a new vector.
def
mapWithIndex
[aefb]
(
f :
Int32 -> (a -> b \ ef)
v :
Vector[a]
)
: Vector[b]
\ ef
Returns the result of applying f
to every element in v
along with that element's index.
That is, the result is of the form: [ f(a[0], 0), f(a[1], 1), ... ]
.
def
maximum
[a]
(
v :
Vector[a]
)
: Option[a]
\ Pure
with
Order[a]
Optionally finds the largest element of v
according to the Order
on v
.
Returns None
if v
is empty.
def
maximumBy
[a]
(
cmp :
a -> (a -> Comparison)
v :
Vector[a]
)
: Option[a]
\ Pure
Optionally finds the largest element of v
according to the given comparator cmp
.
Returns None
if v
is empty.
def
memberOf
[a]
(
x :
a
v :
Vector[a]
)
: Bool
\ Pure
with
Eq[a]
Returns true
if and only if v
contains the element x
.
def
minimum
[a]
(
v :
Vector[a]
)
: Option[a]
\ Pure
with
Order[a]
Optionally finds the smallest element of v
according to the Order
on v
.
Returns None
if v
is empty.
def
minimumBy
[a]
(
cmp :
a -> (a -> Comparison)
v :
Vector[a]
)
: Option[a]
\ Pure
Optionally finds the smallest element of v
according to the given comparator cmp
.
Returns None
if v
is empty.
def
nth
[a]
(
i :
Int32
v :
Vector[a]
)
: Option[a]
\ Pure
Optionally returns the element at position i
in the vector v
.
def
partition
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: (Vector[a], Vector[a])
\ ef
Returns a pair of vectors (v1, v2)
.
v1
contains all elements of v
that satisfy the predicate f
.
v2
contains all elements of v
that do not satisfy the predicate f
.
def
patch
[a]
(
i :
Int32
n :
Int32
a :
Vector[a]
b :
Vector[a]
)
: Vector[a]
\ Pure
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
range
(
b :
Int32
e :
Int32
)
: Vector[Int32]
\ Pure
Returns a vector of all integers between b
(inclusive) and e
(exclusive).
Returns an empty vector if b >= e
.
def
reduceLeft
[aef]
(
f :
a -> (a -> a \ ef)
v :
Vector[a]
)
: Option[a]
\ ef
Applies f
to all elements in v
going from left to right until a single value v
is obtained. Returns Some(v)
.
Returns None
if v
is empty.
def
reduceRight
[aef]
(
f :
a -> (a -> a \ ef)
v :
Vector[a]
)
: Option[a]
\ ef
Applies f
to all elements in v
going from right to left until a single value v
is obtained. Returns Some(v)
.
Returns None
if v
is empty.
def
repeat
[a]
(
n :
Int32
x :
a
)
: Vector[a]
\ Pure
Returns a vector with the element x
repeated n
times.
Returns an empty vector if n <= 0
.
def
replace
[a]
(
from :
{ from = a }
to :
{ to = a }
v :
Vector[a]
)
: Vector[a]
\ Pure
with
Eq[a]
Returns a copy of v
with every occurrence of from
replaced by to
.
def
reverse
[a]
(
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns the reverse of v
.
def
rotateLeft
[a]
(
n :
Int32
v :
Vector[a]
)
: Vector[a]
\ Pure
Rotate the contents of vector v
by n
steps to the left.
def
rotateRight
[a]
(
n :
Int32
v :
Vector[a]
)
: Vector[a]
\ Pure
Rotate the contents of vector v
by n
steps to the right.
def
scan
[baef]
(
f :
b -> (a -> b \ ef)
s :
b
v :
Vector[a]
)
: Vector[b]
\ ef
Alias for scanLeft
.
def
scanLeft
[baef]
(
f :
b -> (a -> b \ ef)
s :
b
v :
Vector[a]
)
: Vector[b]
\ ef
Accumulates the result of applying f
to v
going left to right.
That is, the result is of the form: [s , f(s, x1), f(f(s, x1), x2), ...]
.
def
scanRight
[abef]
(
f :
a -> (b -> b \ ef)
s :
b
v :
Vector[a]
)
: Vector[b]
\ ef
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
sequence
[ma]
(
v :
Vector[m[a]]
)
: m[Vector[a]]
\ Pure
with
Applicative[m]
Returns the result of running all the actions in the list v
going from left
to right.
def
shuffle
[a]
(
rnd :
Random
v :
Vector[a]
)
: Vector[a]
\ IO
Shuffles v
using the Fisher–Yates shuffle.
def
singleton
[a]
(
x :
a
)
: Vector[a]
\ Pure
Returns a singleton vector containing `x``.
def
slice
[a]
(
start :
{ start = Int32 }
end :
{ end = Int32 }
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns a fresh array with the elements from the vector v
from index b
(inclusive) until index e
(exclusive).
def
sort
[a]
(
v :
Vector[a]
)
: Vector[a]
\ Pure
with
Order[a]
Returns a sorted copy of vector v
, 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 v
.
The sort implementation is a Quicksort.
def
sortBy
[ab]
(
f :
a -> b
v :
Vector[a]
)
: Vector[a]
\ Pure
with
Order[b]
Returns a sorted copy of vector v
, 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 v
.
The sort implementation is a Quicksort.
def
sortWith
[a]
(
cmp :
a -> (a -> Comparison)
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns a sorted copy of vector v
, 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 v
.
The sort implementation is a Quicksort.
def
span
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: (Vector[a], Vector[a])
\ ef
Returns a pair of vectors (v1, v2)
.
v1
is the longest prefix of v
that satisfies the predicate f
.
v2
is the remainder of v
.
def
splitAt
[a]
(
n :
Int32
v :
Vector[a]
)
: (Vector[a], Vector[a])
\ Pure
Split the vector v
at the position n
returning the left and right parts.
Position n
is included in the right part.
Example: splitAt(2, Vector#{1, 2, 3, 4})
returns (Vector#{1, 2}, Vector#{3, 4})
Returns (v, Vector#{})
if n > length(xs)
.
Returns (Vector#{}, v)
if n < 0
.
def
sum
(
v :
Vector[Int32]
)
: Int32
\ Pure
Returns the sum of all elements in the vector v
.
def
sumWith
[aef]
(
f :
a -> Int32 \ ef
v :
Vector[a]
)
: Int32
\ ef
Returns the sum of all elements in the vector v
according to the function f
.
def
take
[a]
(
n :
Int32
v :
Vector[a]
)
: Vector[a]
\ Pure
Alias for takeLeft
.
def
takeLeft
[a]
(
n :
Int32
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns a fresh vector taking first n
elements of v
.
Returns a copy of v
if n > length(v)
.
def
takeRight
[a]
(
n :
Int32
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns a fresh vector taking last n
elements of v
.
Returns a copy v
if n > length(v)
.
def
takeWhile
[aef]
(
f :
a -> Bool \ ef
a :
Vector[a]
)
: Vector[a]
\ ef
Alias for takeWhileLeft
.
def
takeWhileLeft
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Vector[a]
\ ef
Returns the longest prefix of v
that satisfies the predicate f
.
def
takeWhileRight
[aef]
(
f :
a -> Bool \ ef
v :
Vector[a]
)
: Vector[a]
\ ef
Returns the longest suffix of v
that satisfies the predicate f
.
def
toArray
[ra]
(
rc :
Region[r]
v :
Vector[a]
)
: Array[a, r]
\ r
Returns the vector v
as an array.
def
toChain
[a]
(
v :
Vector[a]
)
: Chain[a]
\ Pure
Returns the vector v
as a chain.
def
toDelayList
[a]
(
v :
Vector[a]
)
: DelayList[a]
\ Pure
Returns the vector v
as a DelayList
.
def
toList
[a]
(
v :
Vector[a]
)
: List[a]
\ Pure
Returns the vector v
as a list.
def
toMap
[ab]
(
v :
Vector[(a, b)]
)
: Map[a, b]
\ Pure
with
Order[a]
Returns the association vector v
as a map.
If v
contains multiple mappings with the same key, toMap
does not
make any guarantees about which mapping will be in the resulting map.
def
toMutDeque
[ra]
(
rc :
Region[r]
v :
Vector[a]
)
: MutDeque[a, r]
\ r
Returns v
as a MutDeque.
def
toMutList
[ra]
(
rc :
Region[r]
v :
Vector[a]
)
: MutList[a, r]
\ r
Returns the array a
as a MutList.
def
toNec
[a]
(
v :
Vector[a]
)
: Option[Nec[a]]
\ Pure
Optionally returns the vector v
as a non-empty chain.
If v
is empty return None
, otherwise return the Nec wrapped in Some
.
def
toNel
[a]
(
v :
Vector[a]
)
: Option[Nel[a]]
\ Pure
Optionally returns the vector v
as a non-empty list.
If v
is empty return None
, otherwise return the Nel wrapped in Some
.
def
toSet
[a]
(
v :
Vector[a]
)
: Set[a]
\ Pure
with
Order[a]
Returns the vector v
as a set.
def
toString
[a]
(
v :
Vector[a]
)
: String
\ Pure
with
ToString[a]
Returns a string representation of the given vector v
.
def
transpose
[a]
(
vs :
Vector[Vector[a]]
)
: Vector[Vector[a]]
\ Pure
Returns the transpose of vs
.
Returns a non-transposed copy of vs
if the dimensions of the elements of vs
are mismatched.
def
traverse
[aefmb]
(
f :
a -> m[b] \ ef
v :
Vector[a]
)
: m[Vector[b]]
\ ef
with
Applicative[m]
Returns the result of applying the applicative mapping function f
to all the elements of the
vector v
going from left to right.
def
unzip
[ab]
(
v :
Vector[(a, b)]
)
: (Vector[a], Vector[b])
\ Pure
Returns a pair of vectors, the first containing all first components in v
and the second containing all second components in v
.
def
update
[a]
(
i :
Int32
x :
a
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns a copy of v
with the element at index i
replaced by x
.
Returns a copy of v
if i < 0
or i > length(xs)-1
.
def
updateSequence
[a]
(
i :
Int32
sub :
Vector[a]
v :
Vector[a]
)
: Vector[a]
\ Pure
Returns a copy of v
with the elements starting at index i
replaced by sub
.
def
zip
[ab]
(
a :
Vector[a]
b :
Vector[b]
)
: Vector[(a, b)]
\ Pure
Returns a vector 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 vector.
def
zipWith
[abefc]
(
f :
a -> (b -> c \ ef)
a :
Vector[a]
b :
Vector[b]
)
: Vector[c]
\ ef
Returns a vector 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 vector.
def
zipWithA
[abefmc]
(
f :
a -> (b -> m[c] \ ef)
v1 :
Vector[a]
v2 :
Vector[b]
)
: m[Vector[c]]
\ ef
with
Applicative[m]
Generalize zipWith
to an applicative functor f
.