# Vector

## Definitions

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

Return a new vector, appending the elements `v2` after elements of `v1`.

`def compare(a: Vector[a], b: Vector[a]): Comparison with Order[a]`

Compares `a` and `b` lexicographically.

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

Returns the number of elements in `v` that satisfy the predicate `f`.

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

Alias for `dropLeft`.

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

Returns 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]`

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

Alias for `dropWhileLeft`.

`def dropWhileLeft(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(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(): Vector[a]`

Returns an empty (length zero) vector.

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

Alias for `findLeft`.

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

Alias for `findIndexOfLeft`.

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

Optionally returns the position of the first element in `v` satisfying `f`.

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

Returns the positions of the all the elements in `v` satisfying `f`.

`def findLeft(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(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(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(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(vs: Vector[Vector[a]]): Vector[a]`

Returns the concatenation of all the vectors in the vector `vs`.

`def fold(v: Vector[a]): a with Monoid[a]`

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`

Alias for `foldLeft2`.

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

Apply the effectful function `f` to all the elements in the vector `v`.

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

Retrieves the value at position `i` in the vector `v`.

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

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

Returns `Some(x)` if `x` is the first element of `v`.

Returns `None` if `v` is empty.

`def indexOf(x: a, v: Vector[a]): Option[Int32] with Eq[a]`

Alias for `IndexOfLeft`

`def indexOfLeft(a: a, v: Vector[a]): Option[Int32] with Eq[a]`

Optionally returns the position of the first occurrence of `a` in `v` searching from left to right.

`def indexOfRight(a: a, v: Vector[a]): Option[Int32] with Eq[a]`

Optionally returns the position of the first occurrence of `a` in `v` searching from right to left.

`def indices(a: a, v: Vector[a]): Vector[Int32] with Eq[a]`

Return the positions of the all the occurrences of `a` in `v`.

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

Build an vector of length `len` by applying `f` to the successive indices.

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

Returns 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]`

Returns a copy of `v` with `sep` inserted between every two adjacent elements.

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

Returns `true` if the given vector `v` is empty.

`def isInfixOf(a: Vector[a], b: Vector[a]): Bool with Eq[a]`

Returns `true` if and only if `a` is a infix of `b`.

`def isPrefixOf(a: Vector[a], b: Vector[a]): Bool with Eq[a]`

Returns `true` if and only if `a` is a prefix of `b`.

`def isSuffixOf(a: Vector[a], b: Vector[a]): Bool with Eq[a]`

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`

Returns an iterator over `v`

`def join(sep: String, v: Vector[a]): String with ToString[a]`

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`

Returns 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]`

Returns `Some(x)` if `x` is the last element of `v`.

Returns `None` if `v` is empty.

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

Returns the length of the vector `v`.

`def map(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(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(v: Vector[a]): Option[a] with Order[a]`

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

Optionally finds the largest element of `v` according to the given comparator `cmp`.

Returns `None` if `v` is empty.

`def memberOf(x: a, v: Vector[a]): Bool with Eq[a]`

Returns `true` if and only if `v` contains the element `x`.

`def minimum(v: Vector[a]): Option[a] with Order[a]`

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

Optionally finds the smallest element of `v` according to the given comparator `cmp`.

Returns `None` if `v` is empty.

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

Returns `true` if the given vector `v` is non-empty.

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

Optionally returns the element at position `i` in the vector `v`.

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

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

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

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

Returns a vector with the element `x` repeated `n` times.

Returns an empty vector if `n <= 0`.

`def replace(src: { src = a }, dst: { dst = a }, v: Vector[a]): Vector[a] with Eq[a]`

Returns a copy of `v` with every occurrence of `src` replaced by `dst`.

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

Returns the reverse of `v`.

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

Rotate the contents of vector `v` by `n` steps to the left.

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

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

Alias for `scanLeft`.

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

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

Shuffles `v` using the Fisherâ€“Yates shuffle.

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

Returns a singleton vector containing `x``.

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

Returns a fresh array with the elements from the vector `v` from index `b` (inclusive) until index `e` (exclusive).

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

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

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`

Returns the sum of all elements in the vector `v`.

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

Alias for `takeLeft`.

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

Returns 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]`

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

Alias for `takeWhileLeft`.

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

Returns the longest prefix of `v` that satisfies the predicate `f`.

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

Returns the longest suffix of `v` that satisfies the predicate `f`.

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

Returns the vector `v` as an array.

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

Returns the vector `v` as a chain.

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

Returns the vector `v` as a `DelayList`.

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

Returns the vector `v` as a list.

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

Returns `v` as a MutDeque.

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

Returns the array `a` as a MutList.

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

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

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(v: Vector[a]): Set[a] with Order[a]`

Returns the vector `v` as a set.

`def toString(v: Vector[a]): String with ToString[a]`

Returns a string representation of the given vector `v`.

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

Returns 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]`

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

Returns 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]`

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

Returns 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)]`

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(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(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`.