import { $type, Eval, Kind, TyK, TyVar } from '@fp4ts/core'; import { Compare, Eq, Monoid, Ord } from '@fp4ts/cats-kernel'; import { Alternative } from '../../alternative'; import { Applicative } from '../../applicative'; import { CoflatMap } from '../../coflat-map'; import { EqK } from '../../eq-k'; import { Foldable } from '../../foldable'; import { MonoidK } from '../../monoid-k'; import { Monad } from '../../monad'; import { Traversable } from '../../traversable'; import { TraversableFilter } from '../../traversable-filter'; import { Unzip } from '../../unzip'; import { Either } from '../either'; import { Option } from '../option'; import { Map } from './map'; import { Set } from './set'; import { List } from './list'; import { View } from './view'; /** * General purpose, strict, finite sequence of elements `A`. */ export type Seq = _Seq; export declare const Seq: { (...xs: A[]): Seq; empty: any; cons(x: A_1, tl: Seq): Seq; snoc(tl: Seq, x: A_2): Seq; singleton(x: A_3): Seq; range(from: number, until: number): Seq; fromArray(xs: A_4[]): Seq; fromList(xs: List): Seq; fromIterable(xs: Iterable): Seq; fromIterator(it: Iterator): Seq; fromFunction(sz: number, f: (idx: number) => A_8): Seq; tailRecM_(a: A_9, f: (a: A_9) => Seq>): Seq; Eq: (a: Eq) => Eq>; EqK: EqK; Monad: Monad; Alternative: Alternative; Foldable: Foldable; Traversable: Traversable; TraversableFilter: TraversableFilter; CoflatMap: CoflatMap; Unzip: Unzip; }; declare abstract class _Seq { readonly __void: A; /** * _O(1)_ Extracts the first element of the sequence, which must be non-empty. * * @note This function is partial. * * @see headOption for a safe variant * * @examples * * ```typescript * > Seq(1, 2, 3).head * // 1 * * > Seq.empty.head * // Uncaught Error: Seq.empty: head * ``` */ get head(): A; /** * _O(1)_ Safe version of the `head` which optionally returns the first element * of the sequence. * * @examples * * ```typescript * > Seq(1, 2, 3).head * // Some(1) * * > Seq.empty.head * // None * ``` */ get headOption(): Option; /** * _O(1)_ Extracts the elements of the sequence which come after the initial * head. * Equivalent to: * * `xs.tail` is equivalent to `xs.drop(1)`. * * As such, it is safe to perform `tail` on empty sequences as well. * * @examples * *```typescript * > Seq(1, 2, 3).tail * // Seq(2, 3) * * > Seq(1).tail * // Seq() * * > Seq.empty.tail * // Seq() * ``` */ get tail(): Seq; /** * _O(1)_ Optionally decompose the sequence into its head and tail. * Returns `None` if empty. * * @examples * * ```typescript * > Seq(1, 2, 3).uncons * // Some([1, Seq(2, 3)]) * * > Seq(42).uncons * // Some([42, Seq()]) * * > Seq.empty.uncons * // None * ``` */ get uncons(): Option<[A, Seq]>; /** * _O(1)_ Extracts the last element of the sequence, which must be non-empty. * * @note This is a partial function. * * @see lastOption for a safe variant * * @examples * * ```typescript * > Seq(1, 2, 3).last * // 3 * * > Seq(1).last * // 1 * * > Seq.empty.last * // Uncaught Error: Seq.empty: last * ``` */ get last(): A; /** * _O(1)_ Optionally extracts the last element of the sequence. * * @examples * * ```typescript * > Seq(1, 2, 3).last * // Some(3) * * > Seq(1).last * // Some(1) * * > Seq.empty.last * // None * ``` */ get lastOption(): Option; /** * _O(1)_ Extract all elements of the sequence expect from the last one. * * `xs.init` is equivalent to `xs.dropRight(1)` * * @examples * * ```typescript * > Seq(1, 2, 3).init * // Seq(1, 2) * * > Seq(1).init * // Seq() * * > Seq.empty.init * // Seq() * ``` */ get init(): Seq; /** * _O(1)_ Optionally extract init and the last element of the sequence. */ get popLast(): Option<[A, Seq]>; /** * _O(1)_ Returns `true` if the sequence is empty, or `false` otherwise. * * @examples * * ```typescript * > Seq.empty.isEmpty * // true * * > Seq(42).isEmpty * // false * ``` */ get isEmpty(): boolean; /** * _O(1)_ Negation of `isEmpty`: * * ```typescript * xs.nonEmpty == !xs.isEmpty * ``` */ get nonEmpty(): boolean; /** * _O(1)_ Returns the size of the sequence. * * @examples * * ```typescript * > Seq.empty.size * // 0 * * > Seq(42) * // 1 * * > Seq(1, 2, 3) * // 3 * ``` */ abstract readonly size: number; /** * _O(1)_ Return a view of the sequence'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).toSeq * ``` */ get view(): View; /** * _O(1)_ Right-to-left dual to `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(1)_ Convert the seq into an `Option`, returning `Some(head)` in case of * an non-empty seq, or `None` otherwise. * * `xs.toOption` is equivalent to `xs.headOption`. * * @examples * * ```typescript * > Seq(1, 2, 3).toOption * // Some(1) * * > Seq(42).toOption * // Some(42) * * > Seq.empty.toOption * // None * ``` */ get toOption(): Option; /** * _O(1)_ Convert the seq into an `Either`, returning `Right(head)` in case of * an non-empty seq, or `Left(left)` otherwise. * * Equivalent to: * * `xs.toRight(left)` is equivalent to `xs.toOption.toRight(left)` * * @examples * * ```typescript * > Seq(1, 2, 3).toRight(() => 42) * // Right(1) * * > Seq(1).toRight(() => 42) * // Right(1) * * > Seq.empty.toRight(() => 42) * // Left(42) * ``` */ toRight(left: () => E): Either; /** * _O(1)_ Convert the seq into an `Either`, returning `Left(head)` in case of * an non-empty seq, or `Right(right)` otherwise. * * Equivalent to: * * `xs.toLeft(right)` is equivalent to `xs.toOption.toLeft(right)` * * @examples * * ```typescript * > Seq(1, 2, 3).toLeft(() => 42) * // Left(1) * * > Seq(1).toLeft(() => 42) * // Left(1) * * > Seq.empty.toLeft(() => 42) * // Right(42) * ``` */ toLeft(right: () => B): Either; /** * _O(n)_ Converts the seq into a `Set` using provided `Ord` instance, or * `Ord.fromUniversalCompare()` if not provided. * * @examples * * ```typescript * > Seq(1, 2, 3).toSet() * // Set(1, 2, 3) * * > Seq(1, 2, 2, 3, 3).toSet() * // Set(1, 2, 3) * * > Seq.empty.toSet() * // Set() * ``` */ toSet(this: Seq, O?: Ord): Set; /** * _O(n)_ Converts the seq of tuples `[K, V] into a `Map` using provided * `Ord` instance, or `Ord.fromUniversalCompare()` if not provided. * * @examples * * ```typescript * > Seq([1, 'a'], [2, 'b'], [3, 'c']).toMap() * // Map([1, 'a'], [2, 'b'], [3, 'c']) * * > Seq([1, 'a'], [2, 'b'], [2, 'c'], [3, 'd'], [3, 'd']).toMap() * // Map([1, 'a'], [2, 'c'], [3, 'd']) * * > Seq.empty.toMap() * // Map() * ``` */ toMap(this: Seq<[K, V]>, O?: Ord): Map; /** * _O(1)_ Returns an iterator of the elements of the sequence. * * @examples * * ```typescript * > const it = Seq.empty.iterator * > it.next() * // { value: undefined, done: true } * * > const it = Seq(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 sequence. * * @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(1)_ Prepend an element `x` at the beginning of the sequence. * * @examples * * ```typescript * > Seq.empty.prepend(42) * // Seq(42) * * > Seq(1, 2, 3).prepend(42) * // Seq(42, 1, 2, 3) * ``` */ prepend(this: Seq, x: A): Seq; /** * _O(1)_ Appends an element `x` at the end of the sequence. * * @examples * * ```typescript * > Seq.empty.append(42) * // Seq(42) * * > Seq(1, 2, 3).append(42) * // Seq(1, 2, 3, 42) * ``` */ append(this: Seq, x: A): Seq; /** * _O(n)_ Returns `true` if for all elements of the sequence satisfy the * predicate `p`, or `false` otherwise. * * ```typescript * xs.all(p) === !xs.any(x => !p(x)) * ``` * * @examples * * ```typescript * > Seq(1, 2, 3).all(() => true) * // true * * > Seq(1, 2, 3).all(x => x < 3) * // false * * > Seq.empty.all(() => false) * // true * ``` */ all(p: (a: A) => a is B): this is Seq; all(p: (a: A) => boolean): boolean; /** * _O(n)_ Returns `true` if for at least one element of the sequence satisfy * the predicate `p`, or `false` otherwise. * * ```typescript * xs.any(p) == !xs.all(x => !p(x)) * ``` * * @examples * * ```typescript * > Seq(1, 2, 3).any(() => true) * // true * * > Seq(1, 2, 3).any(x => x < 10) * // false * * > Seq.empty.any(() => true) * // false * ``` */ any(p: (a: A) => boolean): boolean; /** * _O(n)_ Returns number of elements of the sequence for which satisfy the * predicate `p`. * * @examples * * ```typescript * > Seq(1, 2, 3).count(x => x >= 2) * // 2 * * > Seq.empty.count(x => true) * // 0 * ``` */ count(p: (a: A) => boolean): number; /** * _O(log(min(i, n - i)))_ Returns prefix of length `i` of the given seq if the * size of the seq is `< i`, otherwise the seq itself. * * @examples * * ```typescript * > Seq(1, 2, 3, 4).take(3) * // Seq(1, 2, 3) * * > Seq(1, 2).take(3) * // Seq(1, 2) * * > Seq.empty.take(3) * // Seq() * * > Seq(1, 2).take(-1) * // Seq() * ``` */ take(i: number): Seq; /** * _O(log(min(i, n - i)))_ Returns suffix of the given seq after the first `i` * elements. * * @examples * * ```typescript * > Seq(1, 2, 3, 4).drop(3) * // Seq(3) * * > Seq(1, 2).drop(3) * // Seq(1, 2) * * > Seq.empty.drop(3) * // Seq() * * > Seq(1, 2).drop(-1) * // Seq(1, 2) * ``` */ drop(i: number): Seq; /** * Combination of `drop` and `take`, equivalent to: * * ```typescript * xs.slice(form, until) === xs.drop(from).take(until - from); * ``` */ slice(from: number, until: number): Seq; /** * _O(log(min(i, n - i)))_ Return a tuple where the first element if the seq'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 * > Seq(1, 2, 3).splitAt(1) * // [Seq(1), Seq(2, 3)] * ``` */ splitAt(i: number): [Seq, Seq]; /** * _O(i)_ where `i` is the prefix length. Returns a longest prefix of elements * satisfying the predicate `p`. * * @examples * * ```typescript * > Seq(1, 2, 3, 4, 1, 2, 3, 4).takeWhile(x => x < 3) * // Seq(1, 2) * * > Seq(1, 2, 3).takeWhile(x => x < 5) * // Seq(1, 2, 3) * * > Seq(1, 2, 3).takeWhile(x => x < 0) * // Seq() * ``` */ takeWhile(p: (a: A) => a is B): Seq; takeWhile(p: (a: A) => boolean): Seq; /** * _O(i)_ where `i` is the prefix length. Returns a remainder of the seq after * removing its longer prefix satisfying the predicate `p`. * * @examples * * ```typescript * > Seq(1, 2, 3, 4, 1, 2, 3, 4).dropWhile(x => x < 3) * // Seq(3, 4, 1, 2, 3, 4) * * > Seq(1, 2, 3).dropWhile(x => x < 5) * // Seq() * * > Seq(1, 2, 3).dropWhile(x => x < 0) * // Seq(1, 2, 3) * ``` */ dropWhile(p: (a: A) => boolean): Seq; /** * _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 * > Seq(1, 2, 3, 4, 1, 2, 3, 4).span(x => x < 3) * // [Seq(1, 2), Seq(3, 4, 1, 2, 3, 4)] * * > Seq(1, 2, 3).span(_ => true) * // [Seq(1, 2, 3), Seq()] * * > Seq(1, 2, 3).span(_ => false) * // [Seq(), Seq(1, 2, 3)] * ``` */ span(p: (a: A) => a is B): [Seq, Seq]; span(p: (a: A) => boolean): [Seq, Seq]; /** * _O(log(min(i, n - i)))_ Returns suffix of length `i` of the given seq if * the size of the seq is `< i`, otherwise the seq itself. * * @examples * * ```typescript * > Seq(1, 2, 3, 4).takeRight(3) * // Seq(2, 3, 4) * * > Seq(1, 2).takeRight(3) * // Seq(1, 2) * * > Seq.empty.takeRight(3) * // Seq() * * > Seq(1, 2).takeRight(-1) * // Seq() * ``` */ takeRight(i: number): Seq; /** * _O(log(min(i, n - i)))_ Returns prefix of the given seq after the last `i` * elements. * * @examples * * ```typescript * > Seq(1, 2, 3, 4).dropRight(3) * // Seq(1) * * > Seq(1, 2).dropRight(3) * // Seq(1, 2) * * > Seq.empty.dropRight(3) * // Seq() * * > Seq(1, 2).dropRight(-1) * // Seq(1, 2) * ``` */ dropRight(n: number): Seq; /** * _O(i)_ where `i` is the suffix length. Returns a longest suffix of elements * satisfying the predicate `p`. * * @examples * * ```typescript * > Seq(1, 2, 3, 4, 1, 2, 3, 4).takeWhileRight(x => x > 1) * // Seq(2, 3, 4) * * > Seq(1, 2, 3).takeWhileRight(x => x < 5) * // Seq(1, 2, 3) * * > Seq(1, 2, 3).takeWhileRight(x => x < 0) * // Seq() * ``` */ takeWhileRight(p: (a: A) => a is B): Seq; takeWhileRight(p: (a: A) => boolean): Seq; /** * _O(i)_ where `i` is the suffix length. Returns a remainder of the seq after * removing its longer suffix satisfying the predicate `p`. * * @examples * * ```typescript * > Seq(1, 2, 3, 4, 1, 2, 3, 4).dropWhile(x => x > 1) * // Seq(1, 2, 3, 4, 1) * * > Seq(1, 2, 3).dropWhile(x => x < 5) * // Seq() * * > Seq(1, 2, 3).dropWhile(x => x < 0) * // Seq(1, 2, 3) * ``` */ dropWhileRight(p: (a: A) => boolean): Seq; /** * _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 sequence. * * `xs.span(p)` is equivalent to `[xs.dropWhileRight(p), xs.takeWhileRight(p)]` * * @examples * * ```typescript * > Seq(1, 2, 3, 4, 1, 2, 3, 4).spanRight(x => x > 3) * // [Seq(4), Seq(1, 2, 3, 4, 1, 2, 3)] * * > Seq(1, 2, 3).spanRight(_ => true) * // [Seq(), Seq(1, 2, 3)] * * > Seq(1, 2, 3).spanRight(_ => false) * // [Seq(1, 2, 3), Seq()] * ``` */ spanRight(p: (a: A) => a is B): [Seq, Seq]; spanRight(p: (a: A) => boolean): [Seq, Seq]; /** * _O(n)_ Returns a view of of all possible prefixes of the sequence, shortest * first. * * @examples * * ```typescript * > Seq(1, 2, 3).inits().toArray * // [Seq(), Seq(1), Seq(1, 2), Seq(1, 2, 3)] * ``` */ inits(): View>; /** * _O(n)_ Returns a view of of all possible suffixes of the sequence, longest * first. * * @examples * * ```typescript * > Seq(1, 2, 3).inits().toArray * // [Seq(1, 2, 3), Seq(1, 2), Seq(1), Seq()] * ``` */ tails(): View>; /** * _O(n)_ Returns `true` if the sequence contains the element `a`, or `false` * otherwise. * * @examples * * ```typescript * > Seq(1, 2, 3).elem(2) * // true * * > Seq(1, 2, 3).elem(-1) * // false * * > Seq([1, 2], [2, 3]).elem( * > [1, 2], * > Eq.tuple(Eq.fromUniversalEquals(), Eq.fromUniversalEquals()), * > ) * // true * ``` */ elem(this: Seq, a: A, E?: Eq): boolean; /** * Negation of `elem`: * * ```typescript * xs.notElem(x) === !xs.elem(x) * ``` */ notElem(this: Seq, a: A, E?: Eq): boolean; /** * _O(n)_ Looks up a key in the association sequence. * * @examples * * ```typescript * > Seq([1, 'one'], [2, 'two'], [3, 'three']).lookup(2) * // Some('two') * * > Seq([1, 'one']).lookup(2) * // None * * > Seq.empty.lookup(2) * // None * ``` */ lookup(this: Seq<[K, V]>, k: K, E?: Eq): Option; /** * _O(n)_ Optionally returns the first element of the structure matching the * predicate `p`. * * @examples * * ```typescript * > Seq(0, 10, 20, 30, 40, 50).find(x => x > 42) * // Some(50) * * > Seq(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 sequence where all elements of the original sequence satisfy * the predicate `p`. * * @examples * * ```typescript * > Seq(1, 2, 3, 4).filter(x => x % 2 === 0) * // Seq(2, 4) * * > Seq.range(1).filter(x => x % 2 === 0).take(3) * // Seq(2, 4, 6) * ``` */ filter(p: (a: A) => a is B): Seq; filter(p: (a: A) => boolean): Seq; /** * _O(n)_ Returns a sequence where all elements of the original sequence do * not satisfy the predicate `p`. * * `xs.filterNot(p)` is equivalent to `xs.filter(x => !p(x))` * * @examples * * ```typescript * > Seq(1, 2, 3, 4).filterNot(x => x % 2 === 0) * // Seq(1, 3) * * > Seq.range(1).filterNot(x => x % 2 === 0).take(3) * // Seq(1, 3, 5) * ``` */ filterNot(p: (a: A) => boolean): Seq; /** * _O(n)_ A version of `map` which can also remove elements of the original * sequence. * * @examples * * ```typescript * > Seq('1', 'Foo', '3') * > .collect(s => Some(parseInt(x)).filterNot(Number.isNaN)) * // Seq(1, 3) * ``` */ collect(f: (a: A) => Option): Seq; /** * _O(n)_ A version of `collect` which drops the remainder of the sequence * starting with the first element for which the function `f` returns `None`. * * @examples * * ```typescript * > Seq('1', 'Foo', '3') * > .collectWhile(s => Some(parseInt(x)).filterNot(Number.isNaN)) * // Seq(1) * ``` */ collectWhile(f: (a: A) => Option): Seq; /** * _O(n)_ A version of `collect` which drops the prefix of the sequence * starting with the last element for which the function `f` returns `None`. * * @examples * * ```typescript * > Seq('1', 'Foo', '3') * > .collectWhileRight(s => Some(parseInt(x)).filterNot(Number.isNaN)) * // Seq(3) * ``` */ collectWhileRight(f: (a: A) => Option): Seq; /** * _O(n)_ Returns a tuple where the first element is a sequence 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 * > Seq(1, 2, 3, 4, 5, 6).partition(x => x % 2 === 0) * // [Seq(2, 4, 6), Seq(1, 3, 5)] * ``` */ partition(p: (a: A) => a is B): [Seq, Seq]; partition(p: (a: A) => boolean): [Seq, Seq]; /** * _O(n)_ Returns a tuple where the first element corresponds to the elements * of the sequence returning `Left` by applying the function `f`, and the * second one those that return `Right`. * * @examples * * ```typescript * > Seq(1, 2, 3, 4, 5, 6).partitionWith(x => * > x % 2 === 0 ? Left(x % 2) : Right(String(x)) * > ) * // [Seq(1, 2, 3), Seq('1', '3', '5')] * ``` */ partitionWith(f: (a: A) => Either): [Seq, Seq]; /** * _O(log(min(i,n - i)))_ Returns an element at the index `idx`. * * @note This function is partial. * * @see getOption for a safe variant. * * @examples * * ```typescript * > Seq(1, 2, 3).get(0) * // 1 * * > Seq(1, 2, 3).get(2) * // 3 * * > Seq(1, 2, 3).get(3) * // Uncaught Error: IndexOutOfBounds * * > Seq(1, 2, 3).get(-1) * // Uncaught Error: IndexOutOfBounds * ``` */ get(i: number): A; /** * Alias for `get`. */ '!!'(i: number): A; /** * _O(log(min(i,n - i)))_ Optionally returns an element at the index `idx`. * * @examples * * ```typescript * > Seq(1, 2, 3).getOption(0) * // Some(1) * * > Seq(1, 2, 3).getOption(2) * // Some(3) * * > Seq(1, 2, 3).getOption(3) * // None * * > Seq(1, 2, 3).getOption(-1) * // None * ``` */ getOption(i: number): Option; /** * Alias for `getOption`. */ '!?'(i: number): Option; /** * _O(log(min(i,n - i)))_ Replace an element at the index `i` with the new * value `x`. * * @note This is a partial function. * * @examples * * ```typescript * > Seq('a', 'b', 'c').replaceAt(0, 'x') * // Seq('x', 'b', 'c') * * > Seq('a', 'b', 'c').replaceAt(2, 'x') * // Seq('a', 'b', 'x') * * > Seq('a', 'b', 'c').replaceAt(3, 'x') * // Uncaught Error: IndexOutOfBounds * * > Seq('a', 'b', 'c').replaceAt(-1, 'x') * // Uncaught Error: IndexOutOfBounds * ``` */ replaceAt(this: Seq, i: number, x: A): Seq; /** * _O(log(min(i,n - i)))_ Transforms an element at the index `i` using the * function `f`. * * @note This is a partial function. * * @examples * * ```typescript * > Seq('a', 'b', 'c').modifyAt(0, c => c.toUpperCase()) * // Seq('A', 'b', 'c') * * > Seq('a', 'b', 'c').modifyAt(2, c => c.toUpperCase()) * // Seq('a', 'b', 'C') * * > Seq('a', 'b', 'c').modifyAt(3, c => c.toUpperCase()) * // Uncaught Error: IndexOutOfBounds * * > Seq('a', 'b', 'c').modifyAt(-1, c => c.toUpperCase()) * // Uncaught Error: IndexOutOfBounds * ``` */ modifyAt(this: Seq, i: number, f: (x: A) => A): Seq; /** * _O(log(min(i,n - i)))_ Inserts an element `x` at the index `i` shifting * the remainder of the sequence. * * @note This is a partial function. * * @examples * * ```typescript * > Seq('a', 'b', 'c').insertAt(0, 'x') * // Seq('x', 'a', 'b', 'c') * * > Seq('a', 'b', 'c').insertAt(2, 'x') * // Seq('a', 'b', 'x', 'c') * * > Seq('a', 'b', 'c').insertAt(3, 'x') * // Seq('a', 'b', 'c', 'x') * * > Seq('a', 'b', 'c').insertAt(4, 'x') * // Uncaught Error: IndexOutOfBounds * * > Seq('a', 'b', 'c').insertAt(-1, 'x') * // Uncaught Error: IndexOutOfBounds * ``` */ insertAt(this: Seq, i: number, x: A): Seq; /** * _O(log(min(i,n - i)))_ Removes an element `x` at the index `i`. * * @note This is a partial function. * * @examples * * ```typescript * > Seq('a', 'b', 'c').removeAt(0).toArray * // ['b', 'c'] * * > Seq('a', 'b', 'c').removeAt(2).toArray * // ['a', 'b'] * * > Seq('a', 'b', 'c').removeAt(3).toArray * // Uncaught Error: IndexOutOfBounds * * > Seq('a', 'b', 'c').removeAt(-1).toArray * // Uncaught Error: IndexOutOfBounds * ``` */ removeAt(i: number): Seq; /** * _O(n)_ Returns the first index of on occurrence of the element `x` in the * sequence, or `None` when it does not exist. * * @see elemIndices to get indices of _all_ occurrences of the element `x`. * * @examples * * ```typescript * > Seq(1, 2, 3, 1, 2, 3).elemIndex(1) * // Some(0) * * > Seq(1, 2, 3).elemIndex(3) * // Some(2) * * > Seq(1, 2, 3).elemIndex(0) * // None * ``` */ elemIndex(this: Seq, x: A, E?: Eq): Option; /** * _O(n)_ Returns the indices of all occurrence of the element `x` in the * sequence. * * @examples * * ```typescript * > Seq(1, 2, 3, 1, 2, 3).elemIndices(1) * // Seq(0, 3) * * > Seq(1, 2, 3).elemIndices(3) * // Seq(2) * * > Seq(1, 2, 3).elemIndices(0) * // Seq() * ``` */ elemIndices(this: Seq, x: A, E?: Eq): Seq; /** * _O(n)_ Returns the last index of on occurrence of the element `x` in the * sequence, or `None` when it does not exist. * * @see elemIndices to get indices of _all_ occurrences of the element `x`. * * @examples * * ```typescript * > Seq(1, 2, 3, 1, 2, 3).elemIndexRight(1) * // Some(3) * * > Seq(1, 2, 3).elemIndexRight(3) * // Some(2) * * > Seq(1, 2, 3).elemIndexRight(0) * // None * ``` */ elemIndexRight(this: Seq, x: A, E?: Eq): Option; /** * _O(n)_ Returns the indices, from right-to-left of all occurrence of the * element `x` in the sequence. * * @examples * * ```typescript * > Seq(1, 2, 3, 1, 2, 3).elemIndicesRight(1) * // Seq(3, 0) * * > Seq(1, 2, 3).elemIndicesRight(3) * // Seq(2) * * > Seq(1, 2, 3).elemIndicesRight(0) * // Seq() * ``` */ elemIndicesRight(this: Seq, x: A, E?: Eq): Seq; /** * _O(n)_ Returns index of the first element satisfying the predicate `p`. * * @examples * * ```typescript * > Seq(1, 2, 3, 1, 2, 3).findIndex(x => x > 1) * // Some(1) * * > Seq(1, 2, 3).findIndex(x => x === 3) * // Some(2) * * > Seq(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 * > Seq(1, 2, 3, 1, 2, 3).findIndices(x => x > 1) * // Seq(1, 2, 4, 5) * * > Seq(1, 2, 3).findIndices(x => x === 3) * // Seq(2) * * > Seq(1, 2, 3).findIndices(x => x > 20) * // Seq() * ``` */ findIndices(p: (a: A) => boolean): Seq; /** * _O(n)_ Returns index of the last element satisfying the predicate `p`. * * @examples * * ```typescript * > Seq(1, 2, 3, 1, 2, 3).findIndex(x => x > 1) * // Some(5) * * > Seq(1, 2, 3).findIndex(x => x === 3) * // Some(2) * * > Seq(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 * > Seq(1, 2, 3, 1, 2, 3).findIndices(x => x > 1) * // Seq(5, 4, 3, 2, 1) * * > Seq(1, 2, 3).findIndices(x => x === 3) * // Seq(2) * * > Seq(1, 2, 3).findIndices(x => x > 20) * // Seq() * ``` */ findIndicesRight(p: (a: A) => boolean): Seq; /** * _O(n)_ Returns sequence with elements in reversed order. * * @examples * * ```typescript * > Seq(1, 2, 3).reverse * // Seq(3, 2, 1) * * > Seq(42).reverse * // Seq(42) * * > Seq.empty.reverse * // Seq() * ``` */ get reverse(): Seq; /** * _O(log(min(n1, n2)))_ Appends all elements of the second sequence. * * @examples * * ```typescript * > Seq(1, 2, 3).concat(Seq(4, 5, 6)) * // Seq(1, 2, 3, 4, 5, 6) * ``` */ concat(this: Seq, that: Seq): Seq; /** * Alias for `concat`. */ '++'(this: Seq, that: Seq): Seq; /** * _O(n)_ Returns a new sequence by transforming each element using the * function `f`. * * @examples * * ```typescript * > Seq('a', 'b', 'c').map(x => x.toUpperCase()) * // Seq('A', 'B', 'C') * * > Seq.empty.map(() => { throw new Error(); }) * // Seq() * * > Seq.range(1, 3).map(x => x + 1) * // Seq(2, 3, 4) * ``` */ map(f: (a: A) => B): Seq; /** * _O(m + n)_ Returns a sequence by transforming combination of elements from * both sequences using the function `f`. * * @examples * * ```typescript * > Seq(1, 2).map2(Seq('a', 'b'), tupled) * // Seq([1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']) * ``` */ map2(that: Seq, f: (a: A, b: B) => C): Seq; /** * Lazy version of `map2`. * * @examples * * ```typescript * > Seq(1, 2).map2Eval(Eval.now(Seq('a', 'b')), tupled).value * // Seq([1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']) * * > Seq.empty.map2Eval(Eval.bottom(), tupled).value * // Seq() * ``` */ 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) => Seq): Seq; /** * _O(n)_ Create a new sequence by transforming each of its * non-empty tails using a function `f`. * * @examples * * ```typescript * > Seq('a', 'b', 'c').coflatMap(xs => xs.size) * // Seq(3, 2, 1) * ``` */ coflatMap(f: (xs: Seq) => B): Seq; /** * Returns a new sequence concatenating its nested sequences. * * `xss.flatten()` is equivalent to `xss.flatMap(id)`. */ flatten(this: Seq>): Seq; /** * _O(n)_ Inserts the given separator `sep` in between each of the elements of * the sequence. * * @examples * * ```typescript * > Seq('a', 'b', 'c').intersperse(',') * // Seq('a', ',', 'b', ',', 'c') * ``` */ intersperse(this: Seq, sep: A): Seq; /** * _O(n * m)_ Transposes rows and columns of the sequence. * * @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 * > Seq(Seq(1, 2, 3), Seq(4, 5, 6)).transpose() * // Seq(Seq(1, 4), Seq(2, 5), Seq(3, 6)) * * > Seq(Seq(10, 11), Seq(20), Seq(), Seq(30, 31, 32)).transpose() * // Seq(Seq(10, 20, 30), Seq(11, 31), Seq(32)) * ``` */ transpose(this: Seq>): Seq>; /** * Returns a view of all subsequences. * * @examples * * ```typescript * > Seq(1, 2, 3).subsequences().toArray * // [Seq(), Seq(1), Seq(2), Seq(1, 2), Seq(3), Seq(1, 3), Seq(2, 3), Seq(1, 2, 3)] * ``` */ subsequences(): View>; private nonEmptySubsequences; /** * _O(min(n, m))_ Returns a sequence of pairs of corresponding elements of each * sequence. * * @examples * * ```typescript * > Seq(1, 2, 3).zip(Seq('a', 'b', 'c')) * // Seq([1, 'a'], [2, 'b'], [3, 'c']) * * > Seq(1, 2, 3).zip(Seq('a', 'b')) * // Seq([1, 'a'], [2, 'b']) * * > Seq('a', 'b').zip(Seq(1, 2, 3)) * // Seq(['a', 1], ['b', 2]) * * > Seq.empty.zip(Seq(1, 2, 3)) * // Seq() * * > Seq(1, 2, 3).zip(Seq.empty) * // Seq() * ``` */ zip(that: Seq): Seq<[A, B]>; /** * Lazy version of `zip` that returns a `View`. */ zipView(that: Seq): 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 * > Seq(1, 2, 3).zipWith(Seq(4, 5, 6), (x, y) => x + y) * // Seq(5, 7, 9) * ``` */ zipWith(that: Seq, f: (a: A, b: B) => C): Seq; private zipWithImpl; /** * Lazy version of `zipWith` that returns a `View`. */ zipWithView(that: Seq, f: (a: A, b: B) => C): View; /** * _O(n)_ Returns a sequence where each element is zipped with its index in * the resulting sequence. * * @examples * * ```typescript * > Seq('a', 'b', 'c').zipWithIndex * // Seq(['a', 0], ['a', 1], ['a', 2]) * * > Seq(1, 2, 3, 4, 5, 6).filter(x => x % 2 === 0).zipWithIndex.take(3) * // Seq([2, 0], [4, 1], [6, 2]) * * > Seq(1, 2, 3, 4, 5, 6).zipWithIndex.filter(([x]) => x % 2 === 0).take(3) * // Seq([2, 1], [4, 3], [6, 5]) * ``` */ get zipWithIndex(): Seq<[A, number]>; /** * Version of `zip` working on three sequences. */ zip3(that: Seq, those: Seq): Seq<[A, B, C]>; /** * Version of `zipView` working on three lists. */ zipView3(that: Seq, those: Seq): View<[A, B, C]>; /** * Version of `zipWith` working on three lists. */ zipWith3(that: Seq, those: Seq, f: (a: A, b: B, c: C) => D): Seq; private zipWith3Impl; /** * Version of `zipWithView` working on three lists. */ zipWithView3(ys: Seq, zs: Seq, f: (a: A, b: B, c: C) => D): View; /** * _O(n)_ Transform a list of pairs into a list with its first components and * a list with its second components. * * @examples * * ```typescript * > Seq(['a', 1], ['b', 2], ['c', 3]).unzip() * // [Seq('a', 'b', 'c'), Seq(1, 2, 3)] * ``` */ unzip(this: Seq): [Seq, Seq]; unzipWith(f: (a: A) => readonly [B, C]): [Seq, Seq]; unzip3(this: Seq): [Seq, Seq, Seq]; unzipWith3(f: (a: A) => readonly [B, C, D]): [Seq, Seq, Seq]; private foldRight2; private foldRight3; /** * _O(n)_ Returns a sequence of cumulative results reduced from left: * * `Seq(x1, x2, ...).scanLeft(z, f)` is equivalent to `Seq(z, f(z, x1), f(f(z, x1), x2), ...)` * * * Relationship with `foldLeft`: * * `xs.scanLeft(z, f).last == xs.foldLeft(z, f)` * * @examples * * ```typescript * > Seq(1, 2, 3).scanLeft(0, (z, x) => z + x) * // Seq(0, 1, 3, 6) * * > Seq.empty.scanLeft(42, (z, x) => z + x) * // Seq(42) * * > Seq.range(1, 5).scanLeft(100, (x, y) => x - y) * // Seq(100, 99, 97, 94, 90) * ``` */ scanLeft(z: B, f: (b: B, a: A) => B): Seq; /** * Variant of `scanLeft` with no initial value. * * @examples * * ```typescript * > Seq(1, 2, 3).scanLeft1((z, x) => z + x) * // Seq(1, 3, 6) * * > Seq.empty.scanLeft1((z, x) => z + x) * // Seq() * * > Seq.range(1, 5).scanLeft1((x, y) => x - y) * // Seq(1, -1, -4, -8) */ scanLeft1(this: Seq, f: (acc: A, x: A) => A): Seq; /** * _O(n)_ Right-to-left dual of `scanLeft`. * * @examples * * ```typescript * > Seq(1, 2, 3).scanRight_(0, (x, z) => x + z) * // Seq(6, 5, 3, 0) * * > Seq.empty.scanRight_(42, (x, z) => x + z) * // Seq(42) * * > Seq.range(1, 5).scanRight_(100, (x, z) => x - z) * // Seq(98, -97, 99, -96, 100) * ``` */ scanRight_(z: B, f: (a: A, b: B) => B): Seq; /** * Version of `scanRight_` with no initial value. * * @examples * * ```typescript * > Seq(1, 2, 3).scanRight1_((x, z) => x + z) * // Seq(6, 5, 3) * * > Seq.empty.scanRight1_((x, z) => x + z) * // Seq() * * > Seq.range(1, 5).scanRight1_((x, z) => x - z) * // Seq(-2, 3, -1, 4) * ``` */ scanRight1_(this: Seq, f: (x: A, acc: A) => A): Seq; /** * _O(n)_ Apply `f` to each element of the sequence 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 `forEach`. */ forEachRight(f: (a: A) => void): void; /** * _O(n)_ Apply a left-associative operator `f` to each element of the sequence * reducing it from left to right: * * ```typescript * Seq(x1, x2, ..., xn) === f( ... f(f(z, x1), x2), ... xn) * ``` * * @examples * * ```typescript * > Seq(1, 2, 3, 4, 5).foldLeft(0, (x, y) => x + y) * // 15 * * > Seq.empty.foldLeft(42, (x, y) => x + y) * // 42 * ``` */ foldLeft(z: B, f: (b: B, a: A) => B): B; /** * _O(n)_ Version of `foldLeft` without initial value and therefore it can be * applied only to non-empty structures. * * @note This function is partial. * * @examples * * ```typescript * > Seq(1, 2, 3).foldLeft1((x, y) => x + y) * // 6 * * > Seq.empty.foldLeft1((x, y) => x + y) * // Uncaught Error: Seq.empty: foldLeft1 * ``` */ foldLeft1(this: Seq, f: (acc: A, x: A) => A): A; /** * _O(n)_ Apply a right-associative operator `f` to each element of the sequence, * reducing it from right to left lazily: * * ```typescript * Seq(x1, x2, ..., xn).foldRight(z, f) === f(x1, Eval.defer(() => f(x2, ... Eval.defer(() => f(xn, z), ... )))) * ``` * * @see foldRight_ for the strict, non-short-circuiting version. * * @examples * * ```typescript * > Seq(false, true, false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value * // true * * > Seq(false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value * // false * * > Seq(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 foldRight1_ for the strict, non-short-circuiting version. * * @examples * * ```typescript * > Seq(1, 2, 3).foldRight1((x, ey) => ey.map(y => x + y)).value * // 6 * * > Seq.empty.foldRight1((x, ey) => ey.map(y => x + y)).value * // Uncaught Error: Seq.empty: foldRight1 * ``` */ foldRight1(this: Seq, f: (a: A, eac: Eval) => Eval): Eval; /** * `xs.foldRightReverse(ez, f)` is equivalent to `xs.reverse.foldRight(ez, f)` */ foldRightReverse(ez: Eval, f: (a: A, eb: Eval) => Eval): Eval; /** * Strict, non-short-circuiting version of the `foldRight`. */ foldRight_(z: B, f: (a: A, b: B) => B): B; /** * Strict, non-short-circuiting version of the `foldRight1`. */ foldRight1_(this: Seq, f: (a: A, acc: A) => A): A; /** * _O(n)_ Right associative, lazy fold mapping each element of the structure * into a monoid `M` and combining their results using `combineEval`. * * `xs.folMap(M, f)` is equivalent to `xs.foldRight(Eval.now(M.empty), (a, eb) => M.combineEval_(f(a), eb)).value` * * @see foldMapK for a version accepting a `MonoidK` instance * @see foldMapLeft for a left-associative, strict variant * * @examples * * ```typescript * > Seq(1, 3, 5).foldMap(Monoid.addition, id) * // 9 * * > Seq(1, 3, 5).foldMap(Monoid.product, id) * // 15 * ``` */ foldMap(M: Monoid, f: (a: A) => M): M; /** * Version of `foldMap` that accepts `MonoidK` instance. */ foldMapK(F: MonoidK, f: (a: A) => Kind): Kind; /** * Left-associative, strict version of `foldMap`. */ foldMapLeft(M: Monoid, f: (a: A) => M): M; private forEachUntil; private forEachUntilRight; /** * _O(n * log(n))_ Return sorted sequence. * * @see sortBy for user-supplied comparison function. * * @examples * * ```typescript * > Seq(1, 6, 4, 3, 2, 5).sort() * // Seq(1, 2, 3, 4, 5, 6) * ``` */ sort(this: Seq, O?: Ord): Seq; /** * _O(n * log(n))_ Return a sequence sorted by comparing results of function `f` * applied to each of the element of the Sequence. * * @examples * * ```typescript * > Seq([2, 'world'], [4, '!'], [1, 'Hello']).sortOn(([fst, ]) => fst) * // Seq([1, 'Hello'], [2, 'world'], [4, '!']]) * ``` */ sortOn(f: (a: A) => B, O?: Ord): Seq; /** * Version of `sort` function using a user-supplied comparator `cmp`. */ sortBy(cmp: (l: A, r: A) => Compare): Seq; /** * Transform each element of the structure into an applicative action and * evaluate them left-to-right combining their result into a `List`. * * `traverse` uses `map2Eval` function of the provided applicative `G` allowing * for short-circuiting. * * @see traverse_ for result-ignoring version. * * @examples * * ```typescript * > Seq(1, 2, 3, 4).traverse(Option.Monad, Some) * // Some(Seq(1, 2, 3, 4)) * * > Seq(1, 2, 3, 4).traverse(Option.Monad, _ => None) * // None * ``` */ traverse(G: Applicative, f: (a: A) => Kind): Kind]>; /** * _O(n)_ Evaluate each applicative action of the structure left-to-right and * combine their results. * * `xs.sequence(G)` is equivalent to `xs.traverse(G, id)`. * * `sequence` uses `map2Eval` function of the provided applicative `G` allowing * for short-circuiting. * * @see sequence_ for result-ignoring version. * * @examples * * ```View * > Seq(Some(1), Some(2), Some(3)).sequence(Option.Monad) * // Some(Seq(1, 2, 3)) * * > Seq(Some(1), Some(2), None).sequence(Option.Monad) * // None * ``` */ sequence(this: Seq>, G: Applicative): Kind]>; /** * Transform each element of the structure into an applicative action and * evaluate them left-to-right ignoring the results. * * `traverse_` uses `map2Eval` function of the provided applicative `G` allowing * for short-circuiting. */ traverse_(G: Applicative, f: (a: A) => Kind): Kind; /** * Evaluate each applicative action of the structure left-to-right ignoring * their results. * * `sequence_` uses `map2Eval` function of the provided applicative `G` allowing * for short-circuiting. */ sequence_(this: List>, G: Applicative): Kind; /** * _O(n)_ Version of `traverse` which removes elements of the original sequence. * * @examples * * ```typescript * > const m: Map = Map([1, 'one'], [3, 'three']) * > Seq(1, 2, 3).traverseFilter( * > Monad.Eval, * > k => Eval.now(m.lookup(k)), * > ).value * // Seq('one', 'three') * ``` */ traverseFilter(G: Applicative, f: (a: A) => Kind]>): Kind]>; join(this: Seq, sep?: string): string; toString(): string; equals(this: Seq, that: Seq, E?: Eq): boolean; } export interface SeqF extends TyK<[unknown]> { [$type]: Seq>; } export {}; //# sourceMappingURL=seq.d.ts.map