# Vector

## Definitions

`def ap(f: Vector[a -> b \ ef], v: Vector[a]): Vector[b] \ ef`

SourceApply 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(v1: Vector[a], v2: Vector[a]): Vector[a]`

SourceReturn a new vector, appending the elements `v2`

after elements of `v1`

.

Compares `a`

and `b`

lexicographically.

`def count(f: a -> Bool \ ef, v: Vector[a]): Int32 \ ef`

SourceReturns the number of elements in `v`

that satisfy the predicate `f`

.

`def drop(n: Int32, v: Vector[a]): Vector[a]`

SourceAlias for `dropLeft`

.

`def dropLeft(n: Int32, v: Vector[a]): Vector[a]`

SourceReturns a copy of vector `v`

, dropping the first `n`

elements.

Returns an empty vector if `n > length(v)`

.

`def dropRight(n: Int32, v: Vector[a]): Vector[a]`

SourceReturns a copy of vector `v`

, dropping the last `n`

elements.

Returns an empty vector if `n > length(v)`

.

`def dropWhile(f: a -> Bool \ ef, v: Vector[a]): Vector[a] \ ef`

SourceAlias for `dropWhileLeft`

.

`def dropWhileLeft(f: a -> Bool \ ef, v: Vector[a]): Vector[a] \ ef`

SourceReturns copy of vector `v`

without the longest prefix that satisfies the predicate `f`

.

`def dropWhileRight(f: a -> Bool \ ef, v: Vector[a]): Vector[a] \ ef`

SourceReturns copy of vector `v`

without the longest suffix that satisfies the predicate `f`

.

`def empty(_unit: Unit): Vector[a]`

SourceReturns an empty (length zero) vector.

`def enumerator(rc: Region[r], v: Vector[a]): Iterator[(Int32, a), r, r] \ r`

SourceReturns an iterator over `v`

zipped with the indices of the elements.

Modifying `a`

while using an iterator has undefined behavior and is dangerous.

Returns `true`

if arrays `a`

and `b`

have the same elements in the same order, i.e. are structurally equal.

`def exists(f: a -> Bool \ ef, v: Vector[a]): Bool \ ef`

SourceReturns `true`

if and only if at least one element in `v`

satisfies the predicate `f`

.

Returns `false`

if `v`

is empty.

`def filter(f: a -> Bool \ ef, v: Vector[a]): Vector[a] \ ef`

SourceReturns an array of every element in `arr`

that satisfies the predicate `f`

.

`def filterMap(f: a -> Option[b] \ ef, v: Vector[a]): Vector[b] \ ef`

SourceCollects the successful results of applying the partial function `f`

to every element in `v`

.

`def find(f: a -> Bool \ ef, v: Vector[a]): Option[a] \ ef`

SourceAlias for `findLeft`

.

`def findIndexOf(f: a -> Bool \ ef, v: Vector[a]): Option[Int32] \ ef`

SourceAlias for `findIndexOfLeft`

.

`def findIndexOfLeft(f: a -> Bool \ ef, v: Vector[a]): Option[Int32] \ ef`

SourceOptionally returns the position of the first element in `v`

satisfying `f`

.

`def findIndexOfRight(f: a -> Bool \ ef, v: Vector[a]): Option[Int32] \ ef`

SourceOptionally returns the position of the first element in `v`

satisfying `f`

searching from right to left.

`def findIndices(f: a -> Bool \ ef, v: Vector[a]): Vector[Int32] \ ef`

SourceReturns the positions of the all the elements in `v`

satisfying `f`

.

`def findLeft(f: a -> Bool \ ef, v: Vector[a]): Option[a] \ ef`

SourceOptionally returns the first element of `v`

that satisfies the predicate `f`

when searching from left to right.

`def findMap(f: a -> Option[b] \ ef, v: Vector[a]): Option[b] \ ef`

SourceReturns 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(f: a -> Bool \ ef, v: Vector[a]): Option[a] \ ef`

SourceOptionally returns the first element of `v`

that satisfies the predicate `f`

when searching from right to left.

`def flatMap(f: a -> Vector[b] \ ef, v: Vector[a]): Vector[b] \ ef`

SourceReturns the result of applying `f`

to every element in `v`

and concatenating the results.

`def flatten(vs: Vector[Vector[a]]): Vector[a]`

SourceReturns the concatenation of all the vectors in the vector `vs`

.

Returns the result of applying `combine`

to all the elements in `v`

, using `empty`

as the initial value.

`def fold2(f: c -> (a -> (b -> c \ ef)), c: c, a: Vector[a], b: Vector[b]): c \ ef`

SourceAlias for `foldLeft2`

.

`def foldLeft(f: b -> (a -> b \ ef), s: b, v: Vector[a]): b \ ef`

SourceApplies `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(f: c -> (a -> (b -> c \ ef)), c: c, a: Vector[a], b: Vector[b]): c \ ef`

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, v: Vector[a]): b \ ef`

SourceApplies `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(f: a -> (b -> (c -> c \ ef)), c: c, a: Vector[a], b: Vector[b]): c \ ef`

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) -> b \ ef), z: b, v: Vector[a]): b \ ef`

SourceApplies `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(f: a -> Bool \ ef, v: Vector[a]): Bool \ ef`

SourceReturns `true`

if and only if all elements in `v`

satisfy the predicate `f`

.

Returns `true`

if `v`

is empty.

`def forEach(f: a -> Unit \ ef, v: Vector[a]): Unit \ ef`

SourceApply the effectful function `f`

to all the elements in the vector `v`

.

`def forEachWithIndex(f: Int32 -> (a -> Unit \ ef), v: Vector[a]): Unit \ ef`

SourceApply the effectful function `f`

to all the elements in the vector `v`

.

`def get(i: Int32, v: Vector[a]): a`

SourceRetrieves the value at position `i`

in the vector `v`

.

`def groupBy(f: a -> (a -> Bool), v: Vector[a]): Vector[Vector[a]]`

SourcePartitions `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(v: Vector[a]): Option[a]`

SourceReturns `Some(x)`

if `x`

is the first element of `v`

.

Returns `None`

if `v`

is empty.

Optionally returns the position of the first occurrence of `a`

in `v`

searching from left to right.

Optionally returns the position of the first occurrence of `a`

in `v`

searching from right to left.

Return the positions of the all the occurrences of `a`

in `v`

.

`def init(f: Int32 -> a \ ef, len: Int32): Vector[a] \ ef`

SourceBuild an vector of length `len`

by applying `f`

to the successive indices.

`def intercalate(sep: Vector[a], vs: Vector[Vector[a]]): Vector[a]`

SourceReturns the concatenation of the elements in `vs`

with the elements
of `sep`

inserted between every two adjacent elements.

`def intersperse(sep: a, v: Vector[a]): Vector[a]`

SourceReturns a copy of `v`

with `sep`

inserted between every two adjacent elements.

`def isEmpty(v: Vector[a]): Bool`

SourceReturns `true`

if the given vector `v`

is empty.

Returns `true`

if and only if `a`

is a infix of `b`

.

Returns `true`

if and only if `a`

is a prefix of `b`

.

Returns `true`

if and only if `a`

is a suffix of `b`

.

`def iterator(rc: Region[r], v: Vector[a]): Iterator[a, r, r] \ r`

SourceReturns an iterator over `v`

Returns the concatenation of the string representation
of each element in `v`

with `sep`

inserted between each element.

`def joinWith(f: a -> String \ ef, sep: String, v: Vector[a]): String \ ef`

SourceReturns the concatenation of the string representation
of each element in `v`

according to `f`

with `sep`

inserted between each element.

`def last(v: Vector[a]): Option[a]`

SourceReturns `Some(x)`

if `x`

is the last element of `v`

.

Returns `None`

if `v`

is empty.

`def length(v: Vector[a]): Int32`

SourceReturns the length of the vector `v`

.

`def map(f: a -> b \ ef, v: Vector[a]): Vector[b] \ ef`

SourceReturns the result of applying `f`

to every element in `v`

.

The result is a new vector.

`def mapWithIndex(f: Int32 -> (a -> b \ ef), v: Vector[a]): Vector[b] \ ef`

SourceReturns 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), ... ]`

.

Optionally finds the largest element of `v`

according to the `Order`

on `v`

.

Returns `None`

if `v`

is empty.

`def maximumBy(cmp: a -> (a -> Comparison), v: Vector[a]): Option[a]`

SourceOptionally finds the largest element of `v`

according to the given comparator `cmp`

.

Returns `None`

if `v`

is empty.

Returns `true`

if and only if `v`

contains the element `x`

.

Optionally finds the smallest element of `v`

according to the `Order`

on `v`

.

Returns `None`

if `v`

is empty.

`def minimumBy(cmp: a -> (a -> Comparison), v: Vector[a]): Option[a]`

SourceOptionally finds the smallest element of `v`

according to the given comparator `cmp`

.

Returns `None`

if `v`

is empty.

`def nth(i: Int32, v: Vector[a]): Option[a]`

SourceOptionally returns the element at position `i`

in the vector `v`

.

`def partition(f: a -> Bool \ ef, v: Vector[a]): (Vector[a], Vector[a]) \ ef`

SourceReturns 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(i: Int32, n: Int32, a: Vector[a], b: Vector[a]): Vector[a]`

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 range(b: Int32, e: Int32): Vector[Int32]`

SourceReturns a vector of all integers between `b`

(inclusive) and `e`

(exclusive).

Returns an empty vector if `b >= e`

.

`def reduceLeft(f: a -> (a -> a \ ef), v: Vector[a]): Option[a] \ ef`

SourceApplies `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(f: a -> (a -> a \ ef), v: Vector[a]): Option[a] \ ef`

SourceApplies `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(n: Int32, x: a): Vector[a]`

SourceReturns a vector with the element `x`

repeated `n`

times.

Returns an empty vector if `n <= 0`

.

Returns a copy of `v`

with every occurrence of `from`

replaced by `to`

.

`def reverse(v: Vector[a]): Vector[a]`

SourceReturns the reverse of `v`

.

`def rotateLeft(n: Int32, v: Vector[a]): Vector[a]`

SourceRotate the contents of vector `v`

by `n`

steps to the left.

`def rotateRight(n: Int32, v: Vector[a]): Vector[a]`

SourceRotate the contents of vector `v`

by `n`

steps to the right.

`def scan(f: b -> (a -> b \ ef), s: b, v: Vector[a]): Vector[b] \ ef`

SourceAlias for `scanLeft`

.

`def scanLeft(f: b -> (a -> b \ ef), s: b, v: Vector[a]): Vector[b] \ ef`

SourceAccumulates 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(f: a -> (b -> b \ ef), s: b, v: Vector[a]): Vector[b] \ ef`

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 sequence(v: Vector[m[a]]): m[Vector[a]] with Applicative[m]`

SourceReturns the result of running all the actions in the list `v`

going from left
to right.

`def shuffle(rnd: Random, v: Vector[a]): Vector[a] \ IO`

SourceShuffles `v`

using the Fisherâ€“Yates shuffle.

`def singleton(x: a): Vector[a]`

SourceReturns a singleton vector containing `x``

.

`def slice(start: { start = Int32 }, end: { end = Int32 }, v: Vector[a]): Vector[a]`

SourceReturns a fresh array with the elements from the vector `v`

from index `b`

(inclusive) until index `e`

(exclusive).

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.

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(cmp: a -> (a -> Comparison), v: Vector[a]): Vector[a]`

SourceReturns 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(f: a -> Bool \ ef, v: Vector[a]): (Vector[a], Vector[a]) \ ef`

SourceReturns 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(n: Int32, v: Vector[a]): (Vector[a], Vector[a])`

SourceSplit 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`

SourceReturns the sum of all elements in the vector `v`

.

`def sumWith(f: a -> Int32 \ ef, v: Vector[a]): Int32 \ ef`

SourceReturns the sum of all elements in the vector `v`

according to the function `f`

.

`def take(n: Int32, v: Vector[a]): Vector[a]`

SourceAlias for `takeLeft`

.

`def takeLeft(n: Int32, v: Vector[a]): Vector[a]`

SourceReturns a fresh vector taking first `n`

elements of `v`

.

Returns a copy of `v`

if `n > length(v)`

.

`def takeRight(n: Int32, v: Vector[a]): Vector[a]`

SourceReturns a fresh vector taking last `n`

elements of `v`

.

Returns a copy `v`

if `n > length(v)`

.

`def takeWhile(f: a -> Bool \ ef, a: Vector[a]): Vector[a] \ ef`

SourceAlias for `takeWhileLeft`

.

`def takeWhileLeft(f: a -> Bool \ ef, v: Vector[a]): Vector[a] \ ef`

SourceReturns the longest prefix of `v`

that satisfies the predicate `f`

.

`def takeWhileRight(f: a -> Bool \ ef, v: Vector[a]): Vector[a] \ ef`

SourceReturns the longest suffix of `v`

that satisfies the predicate `f`

.

`def toArray(rc: Region[r], v: Vector[a]): Array[a, r] \ r`

SourceReturns the vector `v`

as an array.

`def toChain(v: Vector[a]): Chain[a]`

SourceReturns the vector `v`

as a chain.

`def toDelayList(v: Vector[a]): DelayList[a]`

SourceReturns the vector `v`

as a `DelayList`

.

`def toList(v: Vector[a]): List[a]`

SourceReturns the vector `v`

as a list.

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(rc: Region[r], v: Vector[a]): MutDeque[a, r] \ r`

SourceReturns `v`

as a MutDeque.

`def toMutList(rc: Region[r], v: Vector[a]): MutList[a, r] \ r`

SourceReturns the array `a`

as a MutList.

`def toNec(v: Vector[a]): Option[Nec[a]]`

SourceOptionally returns the vector `v`

as a non-empty chain.

If `v`

is empty return `None`

, otherwise return the Nec wrapped in `Some`

.

`def toNel(v: Vector[a]): Option[Nel[a]]`

SourceOptionally returns the vector `v`

as a non-empty list.

If `v`

is empty return `None`

, otherwise return the Nel wrapped in `Some`

.

Returns a string representation of the given vector `v`

.

`def transpose(vs: Vector[Vector[a]]): Vector[Vector[a]]`

SourceReturns the transpose of `vs`

.

Returns a non-transposed copy of `vs`

if the dimensions of the elements of `vs`

are mismatched.

`def traverse(f: a -> m[b] \ ef, v: Vector[a]): m[Vector[b]] \ ef with Applicative[m]`

SourceReturns the result of applying the applicative mapping function `f`

to all the elements of the
vector `v`

going from left to right.

`def unzip(v: Vector[(a, b)]): (Vector[a], Vector[b])`

SourceReturns a pair of vectors, the first containing all first components in `v`

and the second containing all second components in `v`

.

`def update(i: Int32, x: a, v: Vector[a]): Vector[a]`

SourceReturns 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(i: Int32, sub: Vector[a], v: Vector[a]): Vector[a]`

SourceReturns a copy of `v`

with the elements starting at index `i`

replaced by `sub`

.

`def zip(a: Vector[a], b: Vector[b]): Vector[(a, b)]`

SourceReturns 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(f: a -> (b -> c \ ef), a: Vector[a], b: Vector[b]): Vector[c] \ ef`

SourceReturns 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(f: a -> (b -> m[c] \ ef), v1: Vector[a], v2: Vector[b]): m[Vector[c]] \ ef with Applicative[m]`

SourceGeneralize `zipWith`

to an applicative functor `f`

.