import { $type, Eval, Kind, TyK, TyVar } from '@fp4ts/core'; import { Compare, Eq, Monoid, Ord } from '@fp4ts/cats-kernel'; import { Align } from '../../align'; import { Alternative } from '../../alternative'; import { Applicative } from '../../applicative'; import { CoflatMap } from '../../coflat-map'; import { EqK } from '../../eq-k'; import { Foldable } from '../../foldable'; import { Monad } from '../../monad'; import { MonoidK } from '../../monoid-k'; import { Traversable } from '../../traversable'; import { TraversableFilter } from '../../traversable-filter'; import { Unzip } from '../../unzip'; import { Either } from '../either'; import { Ior } from '../ior'; import { Option } from '../option'; import { View } from './view'; import { List } from './list'; import { Map } from './map'; import { Seq } from './seq'; import { Set as CSet } from './set'; /** * Immutable, strict, finite sequence of elements `A`. */ export type Vector = _Vector; export declare const Vector: { (...xs: A[]): Vector; singleton(x: A_1): Vector; fromList(xs: List): Vector; fromArray(xs: A_3[]): Vector; fromIterator(it: Iterator): Vector; fromFoldable(F: Foldable, fa: Kind): Vector; empty: _Vector; tailRecM_(a: A_6, f: (a: A_6) => Vector>): Vector; Eq: (a: Eq) => Eq>; EqK: EqK; Monad: Monad; Alternative: Alternative; Foldable: Foldable; Traversable: Traversable; TraversableFilter: TraversableFilter; CoflatMap: CoflatMap; Align: Align; Unzip: Unzip; }; declare class _Vector { private readonly xs; private readonly start; private readonly end; readonly __void: void; constructor(xs: readonly A[], start: number, end: number); /** * _O(1)_ Extracts the first element of the vector, which must be non-empty. * * @note This function is partial. * * @see {@link headOption} for a safe variant * * @examples * * ```typescript * > Vector(1, 2, 3).head * // 1 * * > Vector.empty.head * // Uncaught Error: Vector.empty: head * ``` */ get head(): A; /** * _O(1)_ Safe version of the `head` which optionally returns the first element * of the vector. * * @examples * * ```typescript * > Vector(1, 2, 3).head * // Some(1) * * > Vector.empty.head * // None * ``` */ get headOption(): Option; /** * _O(1)_ Extracts the elements of the vector which come after the initial * head. * * `xs.tail` is equivalent to `xs.drop(1)`. * * As such, it is safe to perform `tail` on empty sequences as well. * * @examples * *```typescript * > Vector(1, 2, 3).tail * // Vector(2, 3) * * > Vector(1).tail * // Vector() * * > Vector.empty.tail * // Vector() * ``` */ get tail(): Vector; /** * _O(1)_ Optionally decompose the vector into its head and tail. Returns * {@link None} if empty. * * @examples * * ```typescript * > Vector(1, 2, 3).uncons * // Some([1, Vector(2, 3)]) * * > Vector(42).uncons * // Some([42, Vector()]) * * > Vector.empty.uncons * // None * ``` */ get uncons(): Option<[A, Vector]>; /** * _O(1)_ Extracts the last element of the vector, which must be non-empty. * * @note This is a partial function. * * @see {@link lastOption} for a safe variant * * @examples * * ```typescript * > Vector(1, 2, 3).last * // 3 * * > Vector(1).last * // 1 * * > Vector.empty.last * // Uncaught Error: Vector.empty: last * ``` */ get last(): A; /** * _O(1)_ Optionally extracts the last element of the vector. * * @examples * * ```typescript * > Vector(1, 2, 3).last * // Some(3) * * > Vector(1).last * // Some(1) * * > Vector.empty.last * // None * ``` */ get lastOption(): Option; /** * _O(1)_ Extract all elements of the vector expect from the last one. * * `xs.init` is equivalent to `xs.dropRight(1)` * * @examples * * ```typescript * > Vector(1, 2, 3).init * // Vector(1, 2) * * > Vector(1).init * // Vector() * * > Vector.empty.init * // Vector() * ``` */ get init(): Vector; /** * _O(1)_ Optionally extract init and the last element of the vector. */ get popLast(): Option<[A, Vector]>; /** * _O(1)_ Returns `true` if the vector is empty, or `false` otherwise. * * @examples * * ```typescript * > Vector.empty.isEmpty * // true * * > Vector(42).isEmpty * // false * ``` */ get isEmpty(): boolean; /** * _O(1)_ Negation of {@link isEmpty}: * * ```typescript * xs.nonEmpty == !xs.isEmpty * ``` */ get nonEmpty(): boolean; /** * _O(1)_ Returns the size of the vector. * * @examples * * ```typescript * > Vector.empty.size * // 0 * * > Vector(42) * // 1 * * > Vector(1, 2, 3) * // 3 * ``` */ get size(): number; /** * _O(1)_ Return a view of the vector's elements. This function is typically * used to "fuse" transformations without creating intermediate structures: * * ```typescript * xs.map(f).filter(p) === xs.view.map(f).filter(p).toVector * ``` */ get view(): View; /** * _O(1)_ Right-to-left dual to {@link view}. * * ```typescript * xs.reverse.map(f).filter(p) === xs.viewRight.map(f).filter(p).toSeq * ``` */ get viewRight(): View; /** * _O(n)_ Converts the sequence into an array. */ get toArray(): A[]; /** * _O(n)_ Converts the sequence into a list. */ get toList(): List; /** * _O(n)_ Converts the sequence into a sequence. */ get toSeq(): Seq; /** * _O(1)_ Convert the vector into an {@link Option}, returning `Some(head)` in case * of an non-empty vector, or `None` otherwise. * * `xs.toOption` is equivalent to `xs.headOption`. * * @examples * * ```typescript * > Vector(1, 2, 3).toOption * // Some(1) * * > Vector(42).toOption * // Some(42) * * > Vector.empty.toOption * // None * ``` */ get toOption(): Option; /** * _O(1)_ Convert the vector into an {@link Either}, returning `Right(head)` in * case of an non-empty vector, or `Left(left)` otherwise. * * Equivalent to: * * `xs.toRight(left)` is equivalent to `xs.toOption.toRight(left)` * * @examples * * ```typescript * > Vector(1, 2, 3).toRight(() => 42) * // Right(1) * * > Vector(1).toRight(() => 42) * // Right(1) * * > Vector.empty.toRight(() => 42) * // Left(42) * ``` */ toRight(left: () => E): Either; /** * _O(1)_ Convert the vector into an {@link Either}, returning `Left(head)` in * case of an non-empty vector, or `Right(right)` otherwise. * * Equivalent to: * * `xs.toLeft(right)` is equivalent to `xs.toOption.toLeft(right)` * * @examples * * ```typescript * > Vector(1, 2, 3).toLeft(() => 42) * // Left(1) * * > Vector(1).toLeft(() => 42) * // Left(1) * * > Vector.empty.toLeft(() => 42) * // Right(42) * ``` */ toLeft(right: () => B): Either; /** * _O(n)_ Converts the vector into a {@link Set} using provided `Ord` instance, * or {@link Ord.fromUniversalCompare} if not provided. * * @examples * * ```typescript * > Vector(1, 2, 3).toSet() * // Set(1, 2, 3) * * > Vector(1, 2, 2, 3, 3).toSet() * // Set(1, 2, 3) * * > Vector.empty.toSet() * // Set() * ``` */ toSet(this: Seq, O?: Ord): CSet; /** * _O(n)_ Converts the vector of tuples `[K, V] into a {@link Map} using * provided `Ord` instance, or {@link Ord.fromUniversalCompare} if not * provided. * * @examples * * ```typescript * > Vector([1, 'a'], [2, 'b'], [3, 'c']).toMap() * // Map([1, 'a'], [2, 'b'], [3, 'c']) * * > Vector([1, 'a'], [2, 'b'], [2, 'c'], [3, 'd'], [3, 'd']).toMap() * // Map([1, 'a'], [2, 'c'], [3, 'd']) * * > Vector.empty.toMap() * // Map() * ``` */ toMap(this: Seq<[K, V]>, O?: Ord): Map; /** * _O(1)_ Returns an iterator of the elements of the vector. * * @examples * * ```typescript * > const it = Vector.empty.iterator * > it.next() * // { value: undefined, done: true } * * > const it = Vector(1, 2).iterator * > it.next() * // { value: 1, done: false } * > it.next() * // { value: 2, done: false } * > it.next() * // { value: undefined, done: true } * ``` */ get iterator(): Iterator; [Symbol.iterator](): Iterator; /** * _O(n)_ Returns a reversed iterator of the elements of the vector. * * @examples * * ```typescript * > const it = Seq.empty.iterator * > it.next() * // { value: undefined, done: true } * * > const it = Seq(1, 2).iterator * > it.next() * // { value: 2, done: false } * > it.next() * // { value: 1, done: false } * > it.next() * // { value: undefined, done: true } * ``` */ get reverseIterator(): Iterator; /** * _O(n)_ Prepend an element `x` at the beginning of the vector. * * @examples * * ```typescript * > Vector.empty.prepend(42) * // Vector(42) * * > Vector(1, 2, 3).prepend(42) * // Vector(42, 1, 2, 3) * ``` */ prepend(this: Vector, x: A): Vector; /** * _O(n)_ Appends an element `x` at the end of the vector. * * @examples * * ```typescript * > Vector.empty.append(42) * // Vector(42) * * > Vector(1, 2, 3).append(42) * // Vector(1, 2, 3, 42) * ``` */ append(this: Vector, x: A): Vector; /** * _O(n)_ Returns `true` if for all elements of the vector satisfy the * predicate `p`, or `false` otherwise. * * ```typescript * xs.all(p) === !xs.any(x => !p(x)) * ``` * * @examples * * ```typescript * > Vector(1, 2, 3).all(() => true) * // true * * > Vector(1, 2, 3).all(x => x < 3) * // false * * > Vector.empty.all(() => false) * // true * ``` */ all(p: (a: A) => a is B): this is Vector; all(p: (a: A) => boolean): boolean; /** * _O(n)_ Returns `true` if for at least one element of the vector satisfy * the predicate `p`, or `false` otherwise. * * ```typescript * xs.any(p) == !xs.all(x => !p(x)) * ``` * * @examples * * ```typescript * > Vector(1, 2, 3).any(() => true) * // true * * > Vector(1, 2, 3).any(x => x < 10) * // false * * > Vector.empty.any(() => true) * // false * ``` */ any(p: (a: A) => boolean): boolean; /** * _O(n)_ Returns number of elements of the vector for which satisfy the * predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3).count(x => x >= 2) * // 2 * * > Vector.empty.count(x => true) * // 0 * ``` */ count(p: (a: A) => boolean): number; /** * _O(1)_ Returns prefix of length `i` of the given seq if the size of the * vector is `< i`, otherwise the vector itself. * * @examples * * ```typescript * > Vector(1, 2, 3, 4).take(3) * // Vector(1, 2, 3) * * > Vector(1, 2).take(3) * // Vector(1, 2) * * > Vector.empty.take(3) * // Vector() * * > Vector(1, 2).take(-1) * // Vector() * ``` */ take(i: number): Vector; /** * _O(1)_ Returns suffix of the given vector after the first `i` elements. * * @examples * * ```typescript * > Vector(1, 2, 3, 4).drop(3) * // Vector(3) * * > Vector(1, 2).drop(3) * // Vector(1, 2) * * > Vector.empty.drop(3) * // Vector() * * > Vector(1, 2).drop(-1) * // Vector(1, 2) * ``` */ drop(i: number): Vector; /** * Combination of `drop` and `take`, equivalent to: * * ```typescript * xs.slice(from, until) === xs.drop(from).take(until - from); * ``` */ slice(from: number, until: number): Vector; /** * _O(1)_ Return a tuple where the first element if the vectors's prefix of * size `i` and the second element is its remainder. * * `xs.splitAt(i)` is equivalent to `[xs.take(i), xs.drop(i)]` * * ```typescript * > Vector(1, 2, 3).splitAt(1) * // [Vector(1), Vector(2, 3)] * ``` */ splitAt(i: number): [Vector, Vector]; /** * _O(i)_ where `i` is the prefix length. Returns a longest prefix of elements * satisfying the predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 1, 2, 3, 4).takeWhile(x => x < 3) * // Vector(1, 2) * * > Vector(1, 2, 3).takeWhile(x => x < 5) * // Vector(1, 2, 3) * * > Vector(1, 2, 3).takeWhile(x => x < 0) * // Vector() * ``` */ takeWhile(p: (a: A) => a is B): Vector; takeWhile(p: (a: A) => boolean): Vector; /** * _O(i)_ where `i` is the prefix length. Returns a remainder of the vector after * removing its longer prefix satisfying the predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 1, 2, 3, 4).dropWhile(x => x < 3) * // Vector(3, 4, 1, 2, 3, 4) * * > Vector(1, 2, 3).dropWhile(x => x < 5) * // Vector() * * > Vector(1, 2, 3).dropWhile(x => x < 0) * // Vector(1, 2, 3) * ``` */ dropWhile(p: (a: A) => boolean): Vector; /** * _O(i)_ where `i` is the prefix length. Returns a tuple where the first * element is the longest prefix satisfying the predicate `p` and the second * is its remainder. * * `xs.span(p)` is equivalent to `[xs.takeWhile(p), xs.dropWhile(p)]` * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 1, 2, 3, 4).span(x => x < 3) * // [Vector(1, 2), Vector(3, 4, 1, 2, 3, 4)] * * > Vector(1, 2, 3).span(_ => true) * // [Vector(1, 2, 3), Vector()] * * > Vector(1, 2, 3).span(_ => false) * // [Vector(), Vector(1, 2, 3)] * ``` */ span(p: (a: A) => a is B): [Vector, Vector]; span(p: (a: A) => boolean): [Vector, Vector]; /** * _O(1)_ Returns suffix of length `i` of the given vector if the size of the * vector is `< i`, otherwise the vector itself. * * @examples * * ```typescript * > Vector(1, 2, 3, 4).takeRight(3) * // Vector(2, 3, 4) * * > Vector(1, 2).takeRight(3) * // Vector(1, 2) * * > Vector.empty.takeRight(3) * // Vector() * * > Vector(1, 2).takeRight(-1) * // Vector() * ``` */ takeRight(i: number): Vector; /** * _O(1)_ Returns prefix of the given vector after the last `i` elements. * * @examples * * ```typescript * > Vector(1, 2, 3, 4).dropRight(3) * // Vector(1) * * > Vector(1, 2).dropRight(3) * // Vector(1, 2) * * > Vector.empty.dropRight(3) * // Vector() * * > Vector(1, 2).dropRight(-1) * // Vector(1, 2) * ``` */ dropRight(i: number): Vector; /** * _O(i)_ where `i` is the suffix length. Returns a longest suffix of elements * satisfying the predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 1, 2, 3, 4).takeWhileRight(x => x > 1) * // Vector(2, 3, 4) * * > Vector(1, 2, 3).takeWhileRight(x => x < 5) * // Vector(1, 2, 3) * * > Vector(1, 2, 3).takeWhileRight(x => x < 0) * // Vector() * ``` */ takeWhileRight(p: (a: A) => a is B): Vector; takeWhileRight(p: (a: A) => boolean): Vector; /** * _O(i)_ where `i` is the suffix length. Returns a remainder of the vector * after removing its longer suffix satisfying the predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 1, 2, 3, 4).dropWhile(x => x > 1) * // Vector(1, 2, 3, 4, 1) * * > Vector(1, 2, 3).dropWhile(x => x < 5) * // Vector() * * > Vector(1, 2, 3).dropWhile(x => x < 0) * // Vector(1, 2, 3) * ``` */ dropWhileRight(p: (a: A) => boolean): Vector; /** * _O(i)_ where `i` is the prefix length. Returns a tuple where the first * element is the longest prefix satisfying the predicate `p` and the second * is the remainder of the vector. * * `xs.span(p)` is equivalent to `[xs.takeWhileRight(p), xs.dropWhileRight(p)]` * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 1, 2, 3, 4).spanRight(x => x > 3) * // [Vector(4), Vector(1, 2, 3, 4, 1, 2, 3)] * * > Vector(1, 2, 3).spanRight(_ => true) * // [Vector(), Vector(1, 2, 3)] * * > Vector(1, 2, 3).spanRight(_ => false) * // [Vector(1, 2, 3), Vector()] * ``` */ spanRight(p: (a: A) => a is B): [Vector, Vector]; spanRight(p: (a: A) => boolean): [Vector, Vector]; /** * _O(n)_ Returns a view of of all possible prefixes of the vector, shortest * first. * * @examples * * ```typescript * > Vector(1, 2, 3).inits().toArray * // [Vector(), Vector(1), Vector(1, 2), Vector(1, 2, 3)] * ``` */ inits(): View>; /** * _O(n)_ Returns a view of of all possible suffixes of the vector, longest * first. * * @examples * * ```typescript * > Vector(1, 2, 3).inits().toArray * // [Vector(1, 2, 3), Vector(1, 2), Vector(1), Vector()] * ``` */ tails(): View>; /** * _O(n)_ Returns `true` if the vector contains the element `a`, or `false` * otherwise. * * @examples * * ```typescript * > Vector(1, 2, 3).elem(2) * // true * * > Vector(1, 2, 3).elem(-1) * // false * * > Vector([1, 2], [2, 3]).elem( * > [1, 2], * > Eq.tuple(Eq.fromUniversalEquals(), Eq.fromUniversalEquals()), * > ) * // true * ``` */ elem(this: Vector, a: A, E?: Eq): boolean; /** * Negation of `elem`: * * ```typescript * xs.notElem(x) === !xs.elem(x) * ``` */ notElem(this: Vector, a: A, E?: Eq): boolean; /** * _O(n)_ Looks up a key in the association vector. * * @examples * * ```typescript * > Vector([1, 'one'], [2, 'two'], [3, 'three']).lookup(2) * // Some('two') * * > Vector([1, 'one']).lookup(2) * // None * * > Vector.empty.lookup(2) * // None * ``` */ lookup(this: Vector<[K, V]>, k: K, E?: Eq): Option; /** * _O(n)_ Optionally returns the first element of the structure matching the * predicate `p`. * * @examples * * ```typescript * > Vector(0, 10, 20, 30, 40, 50).find(x => x > 42) * // Some(50) * * > Vector(1, 2, 3).find(x => x < 0) * // None * ``` */ find(p: (a: A) => a is B): Option; find(p: (a: A) => boolean): Option; /** * _O(n)_ Returns a vector where all elements of the original vector satisfy * the predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3, 4).filter(x => x % 2 === 0) * // Vector(2, 4) * * > Vector.range(1).filter(x => x % 2 === 0).take(3) * // Vector(2, 4, 6) * ``` */ filter(p: (a: A) => a is B): Vector; filter(p: (a: A) => boolean): Vector; /** * _O(n)_ Returns a vector where all elements of the original vector do * not satisfy the predicate `p`. * * `xs.filterNot(p)` is equivalent to `xs.filter(x => !p(x))` * * @examples * * ```typescript * > Vector(1, 2, 3, 4).filterNot(x => x % 2 === 0) * // Vector(1, 3) * * > Vector.range(1).filterNot(x => x % 2 === 0).take(3) * // Vector(1, 3, 5) * ``` */ filterNot(p: (a: A) => boolean): Vector; /** * _O(n)_ A version of `map` which can also remove elements of the original * vector. * * @examples * * ```typescript * > Vector('1', 'Foo', '3') * > .collect(s => Some(parseInt(x)).filterNot(Number.isNaN)) * // Vector(1, 3) * ``` */ collect(f: (a: A) => Option): Vector; /** * _O(n)_ A version of `collect` which drops the remainder of the vector * starting with the first element for which the function `f` returns `None`. * * @examples * * ```typescript * > Vector('1', 'Foo', '3') * > .collectWhile(s => Some(parseInt(x)).filterNot(Number.isNaN)) * // Vector(1) * ``` */ collectWhile(f: (a: A) => Option): Vector; /** * _O(n)_ A version of `collect` which drops the prefix of the vector * starting with the last element for which the function `f` returns `None`. * * @examples * * ```typescript * > Vector('1', 'Foo', '3') * > .collectWhileRight(s => Some(parseInt(x)).filterNot(Number.isNaN)) * // Vector(3) * ``` */ collectWhileRight(f: (a: A) => Option): Vector; /** * _O(n)_ Returns a tuple where the first element is a vector containing the * elements which satisfy the predicate `p` and the second one which contains * the rest of them. * * `xs.partition(p)` is equivalent to `[xs.filter(p), xs.filterNot(p)]`. * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 5, 6).partition(x => x % 2 === 0) * // [Vector(2, 4, 6), Vector(1, 3, 5)] * ``` */ partition(p: (a: A) => a is B): [Vector, Vector]; partition(p: (a: A) => boolean): [Vector, Vector]; /** * _O(n)_ Returns a tuple where the first element corresponds to the elements * of the vector returning `Left` by applying the function `f`, and the * second one those that return `Right`. * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 5, 6).partitionWith(x => * > x % 2 === 0 ? Left(x % 2) : Right(String(x)) * > ) * // [Vector(1, 2, 3), Vector('1', '3', '5')] * ``` */ partitionWith(f: (a: A) => Either): [Vector, Vector]; /** * _O(1)_ Returns an element at the index `idx`. * * @note This function is partial. * * @see {@link getOption} for a safe variant. * * @examples * * ```typescript * > Vector(1, 2, 3).get(0) * // 1 * * > Vector(1, 2, 3).get(2) * // 3 * * > Vector(1, 2, 3).get(3) * // Uncaught Error: IndexOutOfBounds * * > Vector(1, 2, 3).get(-1) * // Uncaught Error: IndexOutOfBounds * ``` */ get(i: number): A; /** * Alias for {@link get}. */ '!!'(i: number): A; /** * _O(1)_ Optionally returns an element at the index `idx`. * * @examples * * ```typescript * > Vector(1, 2, 3).getOption(0) * // Some(1) * * > Vector(1, 2, 3).getOption(2) * // Some(3) * * > Vector(1, 2, 3).getOption(3) * // None * * > Vector(1, 2, 3).getOption(-1) * // None * ``` */ getOption(i: number): Option; /** * Alias for {@link getOption}. */ '!?'(i: number): Option; /** * _O(n)_ Replace an element at the index `i` with the new value `x`. * * @note This is a partial function. * * @examples * * ```typescript * > Vector('a', 'b', 'c').replaceAt(0, 'x') * // Vector('x', 'b', 'c') * * > Vector('a', 'b', 'c').replaceAt(2, 'x') * // Vector('a', 'b', 'x') * * > Vector('a', 'b', 'c').replaceAt(3, 'x') * // Uncaught Error: IndexOutOfBounds * * > Vector('a', 'b', 'c').replaceAt(-1, 'x') * // Uncaught Error: IndexOutOfBounds * ``` */ replaceAt(this: Vector, i: number, x: A): Vector; /** * _O(n)_ Transforms an element at the index `i` using the function `f`. * * @note This is a partial function. * * @examples * * ```typescript * > Vector('a', 'b', 'c').modifyAt(0, c => c.toUpperCase()) * // Vector('A', 'b', 'c') * * > Vector('a', 'b', 'c').modifyAt(2, c => c.toUpperCase()) * // Vector('a', 'b', 'C') * * > Vector('a', 'b', 'c').modifyAt(3, c => c.toUpperCase()) * // Uncaught Error: IndexOutOfBounds * * > Vector('a', 'b', 'c').modifyAt(-1, c => c.toUpperCase()) * // Uncaught Error: IndexOutOfBounds * ``` */ modifyAt(this: Vector, i: number, f: (a: A) => A): Vector; /** * _O(n)_ Inserts an element `x` at the index `i` shifting * the remainder of the sequence. * * @note This is a partial function. * * @examples * * ```typescript * > Vector('a', 'b', 'c').insertAt(0, 'x') * // Vector('x', 'a', 'b', 'c') * * > Vector('a', 'b', 'c').insertAt(2, 'x') * // Vector('a', 'b', 'x', 'c') * * > Vector('a', 'b', 'c').insertAt(3, 'x') * // Vector('a', 'b', 'c', 'x') * * > Vector('a', 'b', 'c').insertAt(4, 'x') * // Uncaught Error: IndexOutOfBounds * * > Vector('a', 'b', 'c').insertAt(-1, 'x') * // Uncaught Error: IndexOutOfBounds * ``` */ insertAt(this: Vector, i: number, x: A): Vector; /** * _O(n)_ Removes an element `x` at the index `i`. * * @note This is a partial function. * * @examples * * ```typescript * > Vector('a', 'b', 'c').removeAt(0).toArray * // ['b', 'c'] * * > Vector('a', 'b', 'c').removeAt(2).toArray * // ['a', 'b'] * * > Vector('a', 'b', 'c').removeAt(3).toArray * // Uncaught Error: IndexOutOfBounds * * > Vector('a', 'b', 'c').removeAt(-1).toArray * // Uncaught Error: IndexOutOfBounds * ``` */ removeAt(this: Vector, i: number): Vector; /** * _O(n)_ Returns the first index of on occurrence of the element `x` in the * vector, or `None` when it does not exist. * * @see {@link elemIndices} to get indices of _all_ occurrences of the element `x`. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).elemIndex(1) * // Some(0) * * > Vector(1, 2, 3).elemIndex(3) * // Some(2) * * > Vector(1, 2, 3).elemIndex(0) * // None * ``` */ elemIndex(this: Vector, x: A, E?: Eq): Option; /** * _O(n)_ Returns the indices of all occurrence of the element `x` in the * vector. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).elemIndices(1) * // Vector(0, 3) * * > Vector(1, 2, 3).elemIndices(3) * // Vector(2) * * > Vector(1, 2, 3).elemIndices(0) * // Vector() * ``` */ elemIndices(this: Vector, x: A, E?: Eq): Vector; /** * _O(n)_ Returns the last index of on occurrence of the element `x` in the * vector, or `None` when it does not exist. * * @see {@link elemIndices} to get indices of _all_ occurrences of the element `x`. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).elemIndexRight(1) * // Some(3) * * > Vector(1, 2, 3).elemIndexRight(3) * // Some(2) * * > Vector(1, 2, 3).elemIndexRight(0) * // None * ``` */ elemIndexRight(this: Vector, x: A, E?: Eq): Option; /** * _O(n)_ Returns the indices, from right-to-left of all occurrence of the * element `x` in the vector. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).elemIndicesRight(1) * // Vector(3, 0) * * > Vector(1, 2, 3).elemIndicesRight(3) * // Vector(2) * * > Vector(1, 2, 3).elemIndicesRight(0) * // Vector() * ``` */ elemIndicesRight(this: Vector, x: A, E?: Eq): Vector; /** * _O(n)_ Returns index of the first element satisfying the predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).findIndex(x => x > 1) * // Some(1) * * > Vector(1, 2, 3).findIndex(x => x === 3) * // Some(2) * * > Vector(1, 2, 3).findIndex(x => x > 20) * // None * ``` */ findIndex(p: (a: A) => boolean): Option; /** * _O(n)_ Returns indices of all elements satisfying the predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).findIndices(x => x > 1) * // Vector(1, 2, 4, 5) * * > Vector(1, 2, 3).findIndices(x => x === 3) * // Vector(2) * * > Vector(1, 2, 3).findIndices(x => x > 20) * // Vector() * ``` */ findIndices(p: (a: A) => boolean): Vector; /** * _O(n)_ Returns index of the last element satisfying the predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).findIndex(x => x > 1) * // Some(5) * * > Vector(1, 2, 3).findIndex(x => x === 3) * // Some(2) * * > Vector(1, 2, 3).findIndex(x => x > 20) * // None * ``` */ findIndexRight(p: (a: A) => boolean): Option; /** * _O(n)_ Returns indices, right-to-left, of all elements satisfying * the predicate `p`. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).findIndices(x => x > 1) * // Vector(5, 4, 3, 2, 1) * * > Vector(1, 2, 3).findIndices(x => x === 3) * // Vector(2) * * > Vector(1, 2, 3).findIndices(x => x > 20) * // Vector() * ``` */ findIndicesRight(p: (a: A) => boolean): Vector; /** * _O(n)_ Returns vector with elements in reversed order. * * @examples * * ```typescript * > Vector(1, 2, 3).reverse * // Vector(3, 2, 1) * * > Vector(42).reverse * // Vector(42) * * > Vector.empty.reverse * // Vector() * ``` */ get reverse(): Vector; /** * _O(n1 + n2)_ Appends all elements of the second vector. * * @examples * * ```typescript * > Vector(1, 2, 3).concat(Vector(4, 5, 6)) * // Vector(1, 2, 3, 4, 5, 6) * ``` */ concat(this: Vector, that: Vector): Vector; /** * Alias for `concat`. */ '++'(this: Vector, that: Vector): Vector; /** * _O(n)_ Returns a new vector by transforming each element using the * function `f`. * * @examples * * ```typescript * > Vector('a', 'b', 'c').map(x => x.toUpperCase()) * // Vector('A', 'B', 'C') * * > Vector.empty.map(() => { throw new Error(); }) * // Vector() * * > Vector.range(1, 3).map(x => x + 1) * // Vector(2, 3, 4) * ``` */ map(f: (a: A) => B): Vector; /** * _O(m + n)_ Returns a vector by transforming combination of elements from * both vectors using the function `f`. * * @examples * * ```typescript * > Vector(1, 2).map2(Vector('a', 'b'), tupled) * // Vector([1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']) * ``` */ map2(that: Vector, f: (a: A, b: B) => C): Vector; /** * Lazy version of `map2`. * * @examples * * ```typescript * > Vector(1, 2).map2Eval(Eval.now(Vector('a', 'b')), tupled).value * // Vector([1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']) * * > Vector.empty.map2Eval(Eval.bottom(), tupled).value * // Vector() * ``` */ map2Eval(that: Eval>, f: (a: A, b: B) => C): Eval>; /** * Returns a new sequence by transforming each element using the function `f` * and concatenating their results. * * @examples * * ```typescript * > Seq(View.range(1), View.range(10), View.range(100)) * > .flatMap(xs => xs.take(3).toSeq) * // Seq(1, 2, 3, 10, 11, 12, 100, 101, 102) * ``` */ flatMap(f: (a: A) => Vector): Vector; /** * _O(n)_ Create a new vector by transforming each of its * non-empty tails using a function `f`. * * @examples * * ```typescript * > Vector('a', 'b', 'c').coflatMap(xs => xs.size) * // Vector(3, 2, 1) * ``` */ coflatMap(f: (xs: Vector) => B): Vector; /** * Returns a new vector concatenating its nested vectors. * * `xss.flatten()` is equivalent to `xss.flatMap(id)`. */ flatten(this: Vector>): Vector; /** * _O(n)_ Inserts the given separator `sep` in between each of the elements of * the vector. * * @examples * * ```typescript * > Vector('a', 'b', 'c').intersperse(',') * // Vector('a', ',', 'b', ',', 'c') * ``` */ intersperse(this: Vector, sep: A): Vector; /** * _O(n * m)_ Transposes rows and columns of the vector. * * @note This function is total, which means that in case some rows are shorter * than others, their elements are skipped in the result. * * @examples * * ```typescript * > Vector(Vector(1, 2, 3), Vector(4, 5, 6)).transpose() * // Vector(Vector(1, 4), Vector(2, 5), Vector(3, 6)) * * > Vector(Vector(10, 11), Vector(20), Vector(), Vector(30, 31, 32)).transpose() * // Vector(Vector(10, 20, 30), Vector(11, 31), Vector(32)) * ``` */ transpose(this: Vector>): Vector>; /** * _O(min(n, m))_ Returns a vector of pairs of corresponding elements of each * vector. * * @examples * * ```typescript * > Vector(1, 2, 3).zip(Vector('a', 'b', 'c')) * // Vector([1, 'a'], [2, 'b'], [3, 'c']) * * > Vector(1, 2, 3).zip(Vector('a', 'b')) * // Vector([1, 'a'], [2, 'b']) * * > Vector('a', 'b').zip(Vector(1, 2, 3)) * // Vector(['a', 1], ['b', 2]) * * > Vector.empty.zip(Vector(1, 2, 3)) * // Vector() * * > Vector(1, 2, 3).zip(Vector.empty) * // Vector() * ``` */ zip(that: Vector): Vector<[A, B]>; /** * Lazy version of {@link zip} that returns a {@link View}. */ zipView(that: Vector): View<[A, B]>; /** * _O(min(n, m))_ A version of `zip` that takes a user-supplied zipping * function `f`. * * ```typescript * xs.zipWith(ys, tupled) === xs.zip(ys) * xs.zipWith(ys, f) === xs.zip(ys).map(([x, y]) => f(x, y)) * ``` * * @examples * * ```typescript * > Vector(1, 2, 3).zipWith(Vector(4, 5, 6), (x, y) => x + y) * // Vector(5, 7, 9) * ``` */ zipWith(that: Vector, f: (a: A, b: B) => C): Vector; /** * Lazy version of {@link zipWith} that returns a `View`. */ zipWithView(that: Vector, f: (a: A, b: B) => C): View; /** * _O(n)_ Returns a vector where each element is zipped with its index in * the resulting vector. * * @examples * * ```typescript * > Vector('a', 'b', 'c').zipWithIndex * // Vector(['a', 0], ['a', 1], ['a', 2]) * * > Vector(1, 2, 3, 4, 5, 6).filter(x => x % 2 === 0).zipWithIndex.take(3) * // Vector([2, 0], [4, 1], [6, 2]) * * > Vector(1, 2, 3, 4, 5, 6).zipWithIndex.filter(([x]) => x % 2 === 0).take(3) * // Vector([2, 1], [4, 3], [6, 5]) * ``` */ get zipWithIndex(): Vector<[A, number]>; align(that: Vector): Vector>; zipAll(that: Vector, defaultX: A, defaultY: B): Vector<[A, B]>; zipAllWith(that: Vector, defaultX: A, defaultY: B, f: (a: A, b: B) => C): Vector; unzip(this: Vector): [Vector, Vector]; unzipWith(f: (a: A) => readonly [B, C]): [Vector, Vector]; private foldRight2; /** * _O(n)_ Returns a vector of cumulative results reduced from left: * * `Vector(x1, x2, ...).scanLeft(z, f)` is equivalent to `Vector(z, f(z, x1), f(f(z, x1), x2), ...)` * * * Relationship with {@link foldLeft}: * * `xs.scanLeft(z, f).last == xs.foldLeft(z, f)` * * @examples * * ```typescript * > Vector(1, 2, 3).scanLeft(0, (z, x) => z + x) * // Vector(0, 1, 3, 6) * * > Vector.empty.scanLeft(42, (z, x) => z + x) * // Vector(42) * * > Vector.range(1, 5).scanLeft(100, (x, y) => x - y) * // Vector(100, 99, 97, 94, 90) * ``` */ scanLeft(z: B, f: (b: B, a: A) => B): Vector; /** * Variant of {@link scanLeft} with no initial value. * * @examples * * ```typescript * > Vector(1, 2, 3).scanLeft1((z, x) => z + x) * // Vector(1, 3, 6) * * > Vector.empty.scanLeft1((z, x) => z + x) * // Vector() * * > Vector.range(1, 5).scanLeft1((x, y) => x - y) * // Vector(1, -1, -4, -8) */ scanLeft1(this: Vector, f: (acc: A, x: A) => A): Vector; /** * _O(n)_ Right-to-left dual of {@link scanLeft}. * * @examples * * ```typescript * > Vector(1, 2, 3).scanRight_(0, (x, z) => x + z) * // Vector(6, 5, 3, 0) * * > Vector.empty.scanRight_(42, (x, z) => x + z) * // Vector(42) * * > Vector.range(1, 5).scanRight_(100, (x, z) => x - z) * // Vector(98, -97, 99, -96, 100) * ``` */ scanRight_(z: B, f: (a: A, b: B) => B): Vector; /** * Version of {@link scanRight_} with no initial value. * * @examples * * ```typescript * > Vector(1, 2, 3).scanRight1_((x, z) => x + z) * // Vector(6, 5, 3) * * > Vector.empty.scanRight1_((x, z) => x + z) * // Vector() * * > Vector.range(1, 5).scanRight1_((x, z) => x - z) * // Vector(-2, 3, -1, 4) * ``` */ scanRight1_(this: Vector, f: (x: A, acc: A) => A): Vector; /** * _O(n^2)_ Removes duplicate elements from the vector. * * @see {@link distinctBy} for the user supplied equality check. * * @note In case the `Eq` is not provided, the implementation falls back * to default equality comparison with _O(n)_. * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 3, 2, 1, 2, 4, 3, 5).distinct() * // Vector(1, 2, 3, 4, 5) * ``` */ distinct(this: Vector, E?: Eq): Vector; /** * Version of {@link distinct} function using a user-supplied equality check `eq`. */ distinctBy(eq: (x: A, y: A) => boolean): Vector; private distinctPrim; /** * _O(n)_ Removes the first occurrence of `x` in the vector. * * @see {@link removeBy} for the use-supplied comparison function. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).remove(1) * // Vector(2, 3, 1, 2, 3) * * > Vector(2, 3).remove(1) * // Vector(2, 3) * * > Vector().remove(1) * // Vector() * ``` */ remove(this: Vector, x: A, E?: Eq): Vector; /** * Version of {@link remove} function using a user-supplied equality check `eq`. */ removeBy(this: Vector, x: A, eq: (x: A, y: A) => boolean): Vector; /** * _O(n * m)_ A non-associative collection difference. `difference` removes * first occurrence of each element of `that` in the current vector. * * `xs.concat(ys).difference(xs) === ys` * * @see {@link differenceBy} for the user-supplied comparison function. * * @examples * * ```typescript * > Vector(1, 2, 3, 1, 2, 3).difference(Vector(2, 3)) * // Vector(1, 1, 2, 3) * * > Vector(1, 2, 3, 1, 2, 3).difference(Vector(1, 1, 2)) * // Vector(3, 2, 3) * * > Vector.range(1, 9).difference(Vector(1, 2, 3)) * // Vector(4, 5, 6, 7, 8) * ``` */ difference(this: Vector, that: Vector, E?: Eq): Vector; /** * Alias for {@link difference}. */ '\\'(this: Vector, that: Vector, E?: Eq): Vector; /** * Version of {@link difference} that uses user-supplied equality check `eq`. */ differenceBy(this: Vector, that: Vector, eq: (x: A, y: A) => boolean): Vector; /** * _O(max(n, m) * m)_ Creates a union of two vectors. * * Duplicates and the elements from the first vector are removed from the * second one. But if there are duplicates in the original vector, they are * present in the result as well. * * @see {@link unionBy} for the user-supplied equality check. * * @note In case the `Eq` is not provided, the implementation falls back * to default equality comparison with _O(max(n, m))_. * * @examples * * ```typescript * > Vector(1, 2, 3).union(Vector(2, 3, 4)) * // Vector(1, 2, 3, 4) * * > Vector(1, 2, 3).union(Vector(1, 2, 3, 3, 4)) * // Vector(1, 2, 3, 4) * * > Vector(1, 1, 2, 3, 6).union(Vector(2, 3, 4)) * // Vector(1, 1, 2, 3, 6, 4) * * > Vector.range(1).union(Vector.range(1)).take(5) * // Vector(1, 2, 3, 4, 5) * * > Vector(1, 2, 3).union(Vector.rage(1)).take(5) * // Vector(1, 2, 3, 4, 5) * ``` */ union(this: Vector, that: Vector, E?: Eq): Vector; /** * Version of {@link union} that uses a user-supplied equality check `eq`. */ unionBy(this: Vector, that: Vector, eq: (x: A, y: A) => boolean): Vector; private unionPrim; /** * _O(n * m)_ Creates an intersection of two vector. If the first vector * contains duplicates so does the second * * @see {@link intersectBy} for a user-supplied equality check. * * @examples * * ```typescript * > Vector(1, 2, 3, 4).intersect(Vector(2, 4, 6, 8)) * // Vector(2, 4) * * > Vector(1, 1, 2, 3).intersect(Vector(1, 2, 2, 5)) * // Vector(1, 1, 2) * ``` */ intersect(this: Vector, that: Vector, E?: Eq): Vector; /** * Version of {@link intersect} that uses user-supplied equality check `eq`. */ intersectBy(this: Vector, that: Vector, eq: (x: A, y: A) => boolean): Vector; /** * _O(n)_ Apply `f` to each element of the vector for its side-effect. * * @examples * * ```typescript * > let acc = 0; * > List(1, 2, 3, 4, 5).forEach(x => acc += x) * > acc * // 15 * ``` */ forEach(f: (a: A) => void): void; /** * Right-to-left dual of {@link forEach}. */ forEachRight(f: (a: A) => void): void; /** * _O(n)_ Apply a left-associative operator `f` to each element of the vector * reducing it from left to right: * * ```typescript * Vector(x1, x2, ..., xn) === f( ... f(f(z, x1), x2), ... xn) * ``` * * @examples * * ```typescript * > Vector(1, 2, 3, 4, 5).foldLeft(0, (x, y) => x + y) * // 15 * * > Vector.empty.foldLeft(42, (x, y) => x + y) * // 42 * ``` */ foldLeft(z: B, f: (b: B, a: A) => B): B; /** * _O(n)_ Version of {@link foldLeft} without initial value and therefore it * can be applied only to non-empty structures. * * @note This function is partial. * * @examples * * ```typescript * > vector(1, 2, 3).foldLeft1((x, y) => x + y) * // 6 * * > Seq.empty.foldLeft1((x, y) => x + y) * // Uncaught Error: Vector.empty: foldLeft1 * ``` */ foldLeft1(this: Vector, f: (acc: A, x: A) => A): A; /** * _O(n)_ Apply a right-associative operator `f` to each element of the vector, * reducing it from right to left lazily: * * ```typescript * Vector(x1, x2, ..., xn).foldRight(z, f) === f(x1, Eval.defer(() => f(x2, ... Eval.defer(() => f(xn, z), ... )))) * ``` * * @see {@link foldRight_} for the strict, non-short-circuiting version. * * @examples * * ```typescript * > Vector(false, true, false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value * // true * * > Vector(false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value * // false * * > Vector(true).foldRight(Eval.bottom(), (x, r) => x ? Eval.true : r).value * // true * ``` */ foldRight(ez: Eval, f: (a: A, eb: Eval) => Eval): Eval; /** * _O(n)_ Version of `foldRight` without initial value and therefore it can be * applied only to non-empty structures. * * @note This function is partial. * * @see {@link foldRight1_} for the strict, non-short-circuiting version. * * @examples * * ```typescript * > Vector(1, 2, 3).foldRight1((x, ey) => ey.map(y => x + y)).value * // 6 * * > Vector.empty.foldRight1((x, ey) => ey.map(y => x + y)).value * // Uncaught Error: Vector.empty: foldRight1 * ``` */ foldRight1(this: Vector, f: (a: A, r: Eval) => Eval): Eval; /** * Strict, non-short-circuiting version of the {@link foldRight}. */ foldRight_(z: B, f: (a: A, b: B) => B): B; /** * Strict, non-short-circuiting version of the {@link foldRight1}. */ foldRight1_(this: Vector, f: (x: A, acc: A) => A): A; private foldRightReversed; /** * _O(n)_ Right associative, lazy fold mapping each element of the structure * into a monoid `M` and combining their results using {@link Monoid.combineEval}. * * `xs.folMap(M, f)` is equivalent to `xs.foldRight(Eval.now(M.empty), (a, eb) => M.combineEval_(f(a), eb)).value` * * @see {@link foldMapK} for a version accepting a `MonoidK` instance * @see {@link foldMapLeft} for a left-associative, strict variant * * @examples * * ```typescript * > Vector(1, 3, 5).foldMap(Monoid.addition, id) * // 9 * * > Vector(1, 3, 5).foldMap(Monoid.product, id) * // 15 * ``` */ foldMap(M: Monoid, f: (a: A) => M): M; /** * Version of {@link foldMap} that accepts {@link MonoidK} instance. */ foldMapK(F: MonoidK, f: (a: A) => Kind): Kind; /** * Left-associative, strict version of {@link foldMap}. */ foldMapLeft(M: Monoid, f: (a: A) => M): M; /** * _O(n * log(n))_ Return sorted vector. * * @see {@link sortBy} for user-supplied comparison function. * * @examples * * ```typescript * > Vector(1, 6, 4, 3, 2, 5).sort() * // Vector(1, 2, 3, 4, 5, 6) * ``` */ sort(this: Vector, O?: Ord): Vector; /** * _O(n * log(n))_ Return a vector sorted by comparing results of function `f` * applied to each of the element of the vector. * * @examples * * ```typescript * > Vector([2, 'world'], [4, '!'], [1, 'Hello']).sortOn(([fst, ]) => fst) * // Vector([1, 'Hello'], [2, 'world'], [4, '!']]) * ``` */ sortOn(f: (a: A) => B, O?: Ord): Vector; /** * Version of {@link sort} function using a user-supplied comparator `cmp`. */ sortBy(cmp: (l: A, r: A) => Compare): Vector; /** * _O(n)_ Inserts the element at the first position which is less, or equal to * the inserted element. In particular, if the vector is sorted to begin with, * it will remain to be sorted. * * @see {@link insertBy} for user-supplied comparison function. * * @examples * * ```typescript * > Vector(1, 2, 3, 5, 6, 7).insert(4) * // Vector(1, 2, 3, 4, 5, 6, 7) * ``` */ insert(this: Vector, x: A, O?: Ord): Vector; /** * Version of {@link insert} function using a user-supplied comparator `cmp`. */ insertBy(this: Vector, x: A, cmp: (x: A, y: A) => Compare): Vector; /** * Transform each element of the structure into an applicative action and * evaluate them left-to-right combining their result into a `List`. * * `traverse` uses {@link Applicative.map2Eval} function of the provided * applicative `G` allowing for short-circuiting. * * @see {@link traverse_} for result-ignoring version. * * @examples * * ```typescript * > Vector(1, 2, 3, 4).traverse(Option.Monad, Some) * // Some(Vector(1, 2, 3, 4)) * * > Vector(1, 2, 3, 4).traverse(Option.Monad, _ => None) * // None * ``` */ traverse(G: Applicative, f: (a: A) => Kind): Kind]>; /** * Transform each element of the structure into an applicative action and * evaluate them left-to-right ignoring the results. * * `traverse_` uses {@link Applicative.map2Eval} function of the provided * applicative `G` allowing for short-circuiting. */ traverse_(G: Applicative, f: (a: A) => Kind): Kind; /** * _O(n)_ Version of {@link traverse} which removes elements of the original * vector. * * @examples * * ```typescript * > const m: Map = Map([1, 'one'], [3, 'three']) * > Vector(1, 2, 3).traverseFilter( * > Monad.Eval, * > k => Eval.now(m.lookup(k)), * > ).value * // Vector('one', 'three') * ``` */ traverseFilter(G: Applicative, f: (a: A) => Kind]>): Kind]>; join(this: Vector, sep?: string): string; toString(): string; equals(this: Vector, that: Vector, E?: Eq): boolean; } export interface VectorF extends TyK<[unknown]> { [$type]: Vector>; } export {}; //# sourceMappingURL=vector.d.ts.map