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 { Functor } from '../../functor';
import { FunctorFilter } from '../../functor-filter';
import { Monad } from '../../monad';
import { MonoidK } from '../../monoid-k';
import { TraversableFilter } from '../../traversable-filter';
import { Unzip } from '../../unzip';
import { Either } from '../either';
import { Ior } from '../ior';
import { Option } from '../option';
import { Map } from './map';
import { Set as CSet } from './set';
import { View } from './view';
import { NonEmptyList } from './non-empty-list';
import { Seq } from './seq';
/**
* Immutable, strict linked-list collection of ordered elements `A`.
*
* For lazy variants, see `View` and `LazyList`.
*/
export type List = _List;
export declare const List: {
(...xs: readonly A[]): List;
/**
* Creates an empty `List`:
*
* ```typescript
* > List.empty
* // List()
* ```
*/
empty: List;
cons(x: A_1, xs: List): List;
/**
* Construct a singleton `List`.
*/
singleton(x: A_2): List;
/**
* Create a list of numbers starting at `from` lower bounds and ended by `to - 1`.
*
* @examples
*
* ```typescript
* > List.range(0, 5)
* // List(0, 1, 2, 3, 4)
*
* > List.range(5, 5)
* // List()
*
* > List.range(5, 0)
* // List()
* ```
*/
range(from: number, until: number): List;
/**
* Dual to `foldRight` function: while `foldRight` reduces the structure into
* a single result, `unfoldRight` build a list from the seed value `z` and a
* function `f`. The build ends once function `f` returns `None`.
*
* @examples
*
* ```typescript
* > List.unfoldRight(10, x => x > 0 ? Some([x, x - 1]) : None);
* // List(10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
* ```
*/
unfoldRight(z: B, f: (b: B) => Option<[A_3, B]>): List;
/**
* Constructs a list from an array.
*/
fromArray(xs: readonly A_4[]): List;
/**
* Constructs a list from an iterable collection.
*/
fromIterable(xs: Iterable): List;
/**
* Constructs a list from an iterator.
*/
fromIterator(it: Iterator): List;
tailRecM_(a: A_7, f: (a: A_7) => List>): List;
Eq(E: Eq): Eq>;
EqK: EqK;
Align: Align;
Unzip: Unzip;
MonoidK: MonoidK;
Functor: Functor;
FunctorFilter: FunctorFilter;
Applicative: Applicative;
Alternative: Alternative;
Monad: Monad;
CoflatMap: CoflatMap;
Foldable: Foldable;
TraversableFilter: TraversableFilter;
};
export declare abstract class _List {
readonly __void: A;
/**
* _O(1)_ Extracts the first element of the list, which must be non-empty.
*
* @note This function is partial.
*
* @see headOption for a safe variant
*
* @examples
*
* ```typescript
* > List(1, 2, 3).head
* // 1
*
* > List.empty.head
* // Uncaught Error: List.head: empty List
* ```
*/
abstract readonly head: A;
/**
* _O(1)_ Extracts the elements of the list which come after the initial head.
* Equivalent to:
*
* ```typescript
* xs.tail == xs.drop(1)
* ```
*
* As such, it is safe to perform `tail` on empty lists as well.
*
* @examples
*
*```typescript
* > List(1, 2, 3).tail
* // List(2, 3)
*
* > List(1).tail
* // List()
*
* > List.empty.tail
* // List()
* ```
*/
abstract readonly tail: List;
/**
* _O(1)_ Safe version of the `head` which optionally returns the first element
* of the list.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).head
* // Some(1)
*
* > List.empty.head
* // None
* ```
*/
get headOption(): Option;
/**
* _O(1)_ Optionally decompose the list into its head and tail. Returns `None`
* if empty.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).uncons
* // Some([1, List(2, 3)])
*
* > List(42).uncons
* // Some([42, List()])
*
* > List.empty.uncons
* // None
* ```
*/
get uncons(): Option<[A, List]>;
/**
* Alias for `uncons`.
*/
get popHead(): Option<[A, List]>;
/**
* _O(n)_ Extracts the last element of the list, which must be non-empty.
*
* @note This is a partial function.
*
* @see lastOption for a safe variant
*
* @examples
*
* ```typescript
* > List(1, 2, 3).last
* // 3
*
* > List(1).last
* // 1
*
* > List.empty.last
* // Uncaught Error: Nil.last
* ```
*/
get last(): A;
/**
* _O(n)_ Optionally extracts the last element of the list.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).last
* // Some(3)
*
* > List(1).last
* // Some(1)
*
* > List.empty.last
* // None
* ```
*/
get lastOption(): Option;
/**
* _O(n)_ Extract all elements of the list expect from the last one.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).init
* // List(1, 2)
*
* > List(1).init
* // List()
*
* > List.empty.init
* // List()
* ```
*/
get init(): List;
/**
* _O(n)_ Optionally extract init and the last element of the list.
*/
get popLast(): Option<[A, List]>;
/**
* _O(1)_ Returns `true` if the list is empty, or `false` otherwise.
*
* @examples
*
* ```typescript
* > List.empty.isEmpty
* // true
*
* > List(1).isEmpty
* // false
* ```
*/
get isEmpty(): boolean;
/**
* _O(1)_ Negation of `isEmpty`:
*
* ```typescript
* xs.nonEmpty == !xs.isEmpty
* ```
*/
get nonEmpty(): boolean;
/**
* _O(n)_ Returns the size of the list.
*
* @examples
*
* ```typescript
* > List.empty.size
* // 0
*
* > List(42)
* // 1
*
* > List(1, 2, 3)
* // 3
* ```
*/
get size(): number;
/**
* _O(1)_ Return a view of the list'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).toList
* ```
*/
get view(): View;
/**
* _O(n)_ Converts the list into an array.
*/
get toArray(): A[];
/**
* _O(n)_ Converts the list into a sequence.
*/
get toSeq(): Seq;
/**
* _O(1)_ Optionally coverts into a non-empty list.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).toNel
* // Some(NonEmptyList(1, 2, 3))
*
* > List(42).toNel
* // Some(NonEmptyList(42))
*
* > List.empty.toNel
* // None
* ```
*/
get toNel(): Option>;
/**
* _O(1)_ Convert the list into an `Option`, returning `Some(head)` in case of
* an non-empty list, or `None` otherwise.
*
* `xs.toOption` is equivalent to `xs.headOption`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).toOption
* // Some(1)
*
* > List(42).toOption
* // Some(42)
*
* > List.empty.toOption
* // None
* ```
*/
get toOption(): Option;
/**
* _O(1)_ Convert the list into an `Either`, returning `Right(head)` in case of
* an non-empty list, or `Left(left)` otherwise.
*
* Equivalent to:
*
* `xs.toRight(left)` is equivalent to `xs.toOption.toRight(left)`
*
* @examples
*
* ```typescript
* > List(1, 2, 3).toRight(() => 42)
* // Right(1)
*
* > List(1).toRight(() => 42)
* // Right(1)
*
* > List.empty.toRight(() => 42)
* // Left(42)
* ```
*/
toRight(left: () => E): Either;
/**
* _O(1)_ Convert the list into an `Either`, returning `Left(head)` in case of
* an non-empty list, or `Right(right)` otherwise.
*
* Equivalent to:
*
* `xs.toLeft(right)` is equivalent to `xs.toOption.toLeft(right)`
*
* @examples
*
* ```typescript
* > List(1, 2, 3).toLeft(() => 42)
* // Left(1)
*
* > List(1).toLeft(() => 42)
* // Left(1)
*
* > List.empty.toLeft(() => 42)
* // Right(42)
* ```
*/
toLeft(right: () => B): Either;
/**
* _O(n)_ Converts the list into a `Set` using provided `Ord` instance, or
* `Ord.fromUniversalCompare()` if not provided.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).toSet()
* // Set(1, 2, 3)
*
* > List(1, 2, 2, 3, 3).toSet()
* // Set(1, 2, 3)
*
* > List.empty.toSet()
* // Set()
* ```
*/
toSet(this: List, O?: Ord): CSet;
/**
* _O(n)_ Converts the list of tuples `[K, V] into a `Map` using provided
* `Ord` instance, or `Ord.fromUniversalCompare()` if not provided.
*
* @examples
*
* ```typescript
* > List([1, 'a'], [2, 'b'], [3, 'c']).toMap()
* // Map([1, 'a'], [2, 'b'], [3, 'c'])
*
* > List([1, 'a'], [2, 'b'], [2, 'c'], [3, 'd'], [3, 'd']).toMap()
* // Map([1, 'a'], [2, 'c'], [3, 'd'])
*
* > List.empty.toMap()
* // Map()
* ```
*/
toMap(this: List<[K, V]>, O?: Ord): Map;
/**
* _O(1)_ Returns an iterator of the elements of the list.
*
* @examples
*
* ```typescript
* > const it = List.empty.iterator
* > it.next()
* // { value: undefined, done: true }
*
* > const it = List(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 list.
*
* @examples
*
* ```typescript
* > const it = List.empty.iterator
* > it.next()
* // { value: undefined, done: true }
*
* > const it = List(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 list.
*
* @examples
*
* ```typescript
* > List.empty.prepend(42)
* // List(42)
*
* > List(1, 2, 3).prepend(42)
* // List(42, 1, 2, 3)
* ```
*/
prepend(this: List, x: A): List;
/**
* Alias for `prepend`.
*/
cons(this: List, x: A): List;
/**
* _O(n)_ Appends an element `x` at the end of the list.
*
* @examples
*
* ```typescript
* > List.empty.append(42)
* // List(42)
*
* > List(1, 2, 3).append(42)
* // List(1, 2, 3, 42)
* ```
*/
append(this: List, x: A): List;
/**
* _O(n)_ Returns `true` if for all elements of the list satisfy the predicate
* `p`, or `false` otherwise.
*
* ```typescript
* xs.all(p) === !xs.any(x => !p(x))
* ```
*
* @examples
*
* ```typescript
* > List(1, 2, 3).all(() => true)
* // true
*
* > List(1, 2, 3).all(x => x < 3)
* // false
*
* > List.empty.all(() => false)
* // true
* ```
*/
all(p: (a: A) => a is B): this is List;
all(p: (a: A) => boolean): boolean;
/**
* _O(n)_ Returns `true` if for at least one element of the list satisfy the
* predicate `p`, or `false` otherwise.
*
* ```typescript
* xs.any(p) == !xs.all(x => !p(x))
* ```
*
* @examples
*
* ```typescript
* > List(1, 2, 3).any(() => true)
* // true
*
* > List(1, 2, 3).any(x => x < 10)
* // false
*
* > List.empty.any(() => true)
* // false
* ```
*/
any(p: (a: A) => boolean): boolean;
/**
* _O(n)_ Returns number of elements of the list for which satisfy the
* predicate `p`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).count(x => x >= 2)
* // 2
*
* > List.empty.count(x => true)
* // 0
* ```
*/
count(p: (a: A) => boolean): number;
/**
* _O(n)_ Returns max element of the non-empty list, using the provided `Ord`
* instance, or `Ord.fromUniversalCompare()` if not provided.
*
* @note This function is partial.
*
* @see maxBy for user-supplied comparison function.
* @see maxOption for a safe variant.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).max()
* // 3
*
* > List.empty.max()
* // Uncaught Error: Nil.max
* ```
*/
max(this: List, O?: Ord): A;
/**
* Version of `max` function using a user-supplied comparator `cmp`.
*
* @note This function is partial.
*
* @see maxByOption for a safe variant.
*/
maxBy(cmp: (l: A, r: A) => Compare): A;
/**
* _O(n)_ Optionally returns max element of the empty list, using the provided
* `Ord` instance, or `Ord.fromUniversalCompare()` if not provided.
*
* @see maxOptionBy for user-supplied comparison function.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).maxOption()
* // Some(3)
*
* > List.empty.maxOption()
* // None
* ```
*/
maxOption(this: List, O?: Ord): Option;
/**
* Version of `maxOption` function using a user-supplied comparator `cmp`.
*/
maxOptionBy(cmp: (l: A, r: A) => Compare): Option;
/**
* _O(n)_ Returns min element of the non-empty list, using the provided `Ord`
* instance, or `Ord.fromUniversalCompare()` if not provided.
*
* @note This function is partial.
*
* @see maxBy for user-supplied comparison function.
* @see minOption for a safe variant.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).min()
* // 1
*
* > List.empty.min()
* // Uncaught Error: Nil.min
* ```
*/
min(this: List, O?: Ord): A;
/**
*Version of `min` function using a user-supplied comparator `cmp`.
*
* @note This function is partial.
*
* @see minOptionBy for a safe variant.
*/
minBy(this: List, cmp: (l: A, r: A) => Compare): A;
/**
* _O(n)_ Optionally returns min element of the empty list, using the provided
* `Ord` instance, or `Ord.fromUniversalCompare()` if not provided.
*
* @see maxOptionBy for user-supplied comparison function.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).minOption()
* // Some(1)
*
* > List.empty.minOption()
* // None
* ```
*/
minOption(this: List, O?: Ord): Option;
/**
* Version of `minOption` function using a user-supplied comparator `cmp`.
*/
minOptionBy(this: List, cmp: (l: A, r: A) => Compare): Option;
/**
* _O(n)_ Returns sum of the elements of the list.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4, 5).sum()
* // 15
*
* > List.empty.sum()
* // 0
* ```
*/
sum(this: List): number;
/**
* _O(n)_ Returns product of the elements of the list.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).product()
* // 120
*
* > View.empty.product()
* // 1
* ```
*/
product(this: List): number;
/**
* Returns prefix of length `n` of the given list if the size of the list is
* `< n`, otherwise the list itself.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4).take(3)
* // List(1, 2, 3)
*
* > List(1, 2).take(3)
* // List(1, 2)
*
* > List.empty.take(3)
* // List()
*
* > List(1, 2).take(-1)
* // List()
* ```
*/
take(n: number): List;
/**
* Returns suffix of the given list after the first `n` elements.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4).drop(3)
* // List(3)
*
* > List(1, 2).drop(3)
* // List(1, 2)
*
* > List.empty.drop(3)
* // List()
*
* > List(1, 2).drop(-1)
* // List(1, 2)
* ```
*/
drop(n: number): List;
/**
* Combination of `drop` and `take`, equivalent to:
*
* ```typescript
* xs.slice(from, until) === xs.drop(from).take(until - from);
* ```
*/
slice(from: number, until: number): List;
/**
* Return a tuple where the first element if the list's prefix of size `n`
* and the second element is its remainder.
*
* `xs.splitAt(n)` is equivalent to `[xs.take(n), xs.drop(n)]
*
* ```typescript
* > List(1, 2, 3).splitAt(1)
* // [List(1), List(2, 3)]
* ```
*/
splitAt(n: number): [List, List];
/**
* Returns a longest prefix of elements satisfying the predicate `p`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4, 1, 2, 3, 4).takeWhile(x => x < 3)
* // List(1, 2)
*
* > List(1, 2, 3).takeWhile(x => x < 5)
* // List(1, 2, 3)
*
* > List(1, 2, 3).takeWhile(x => x < 0)
* // List()
* ```
*/
takeWhile(p: (a: A) => a is B): List;
takeWhile(p: (a: A) => boolean): List;
/**
* Returns a remainder of the list after removing its longer prefix satisfying
* the predicate `p`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4, 1, 2, 3, 4).dropWhile(x => x < 3)
* // List(3, 4, 1, 2, 3, 4)
*
* > List(1, 2, 3).dropWhile(x => x < 5)
* // List()
*
* > List(1, 2, 3).dropWhile(x => x < 0)
* // List(1, 2, 3)
* ```
*/
dropWhile(p: (a: A) => boolean): List;
/**
* 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
* > List(1, 2, 3, 4, 1, 2, 3, 4).span(x => x < 3)
* // [List(1, 2), List(3, 4, 1, 2, 3, 4)]
*
* > List(1, 2, 3).span(_ => true)
* // [List(1, 2, 3), List()]
*
* > List(1, 2, 3).span(_ => false)
* // [List(), List(1, 2, 3)]
* ```
*/
span(p: (a: A) => a is B): [List, List];
span(p: (a: A) => boolean): [List, List];
/**
* Returns suffix of length `n` of the given list if the size of the list is
* `< n`, otherwise the list itself.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4).takeRight(3)
* // List(2, 3, 4)
*
* > List(1, 2).takeRight(3)
* // List(1, 2)
*
* > List.empty.takeRight(3)
* // List()
*
* > List(1, 2).takeRight(-1)
* // List()
* ```
*/
takeRight(n: number): List;
/**
* Returns prefix of the given list after the last `n` elements.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4).dropRight(3)
* // List(1)
*
* > List(1, 2).dropRight(3)
* // List(1, 2)
*
* > List.empty.dropRight(3)
* // List()
*
* > List(1, 2).dropRight(-1)
* // List(1, 2)
* ```
*/
dropRight(n: number): List;
/**
* _O(n^2)_ Returns a view of of all possible prefixes of the list, shortest
* first.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).inits().toArray
* // [List(), List(1), List(1, 2), List(1, 2, 3)]
* ```
*/
inits(): View>;
/**
* _O(n)_ Returns a view of of all possible suffixes of the list, longest
* first.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).inits().toArray
* // [List(1, 2, 3), List(2, 3), List(3), List()]
* ```
*/
tails(): View>;
/**
* _O(n)_ Returns `true` if the list contains the element `a`, or `false`
* otherwise.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).elem(2)
* // true
*
* > List(1, 2, 3).elem(-1)
* // false
*
* > List([1, 2], [2, 3]).elem(
* > [1, 2],
* > Eq.tuple(Eq.fromUniversalEquals(), Eq.fromUniversalEquals()),
* > )
* // true
* ```
*/
elem(this: List, a: A, E?: Eq): boolean;
/**
* Negation of `elem`:
*
* ```typescript
* xs.notElem(x) === !xs.elem(x)
* ```
*/
notElem(this: List, a: A, E?: Eq): boolean;
/**
* _O(n)_ Looks up a key in the association list.
*
* @examples
*
* ```typescript
* > List([1, 'one'], [2, 'two'], [3, 'three']).lookup(2)
* // Some('two')
*
* > List([1, 'one']).lookup(2)
* // None
*
* > List.empty.lookup(2)
* // None
* ```
*/
lookup(this: List, k: K, E?: Eq): Option;
/**
* _O(n)_ Optionally returns the first element of the structure matching the
* predicate `p`.
*
* @examples
*
* ```typescript
* > List(0, 10, 20, 30, 40, 50).find(x => x > 42)
* // Some(50)
*
* > List(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 list where all elements of the original list satisfy the
* predicate `p`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4).filter(x => x % 2 === 0)
* // List(2, 4)
*
* > List.range(1).filter(x => x % 2 === 0).take(3)
* // List(2, 4, 6)
* ```
*/
filter(p: (a: A) => a is B): List;
filter(p: (a: A) => boolean): List;
/**
* _O(n)_ Returns a list where all elements of the original list do not satisfy
* the predicate `p`.
*
* `xs.filterNot(p)` is equivalent to `xs.filter(x => !p(x))`
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4).filterNot(x => x % 2 === 0)
* // List(1, 3)
*
* > List.range(1).filterNot(x => x % 2 === 0).take(3)
* // List(1, 3, 5)
* ```
*/
filterNot(p: (a: A) => boolean): List;
private filterNoneIn;
private static _filterAllIn;
private static _filterPartialFill;
/**
* _O(n)_ A version of `map` which removes elements of the original list.
*
* If the function `f` is a combination of a predicate `p: (a: A) => boolean`
* that determines whether or not a particular element should be kept in the
* resulting list, and a transformation `g: (a: A) => B`, then `xs.collect(f)`
* is equivalent to `xs.filter(p).map(f)`.
*
* @examples
*
* ```typescript
* > List('1', 'Foo', '3')
* > .collect(s => Some(parseInt(x)).filterNot(Number.isNaN))
* // List(1, 3)
* ```
*/
collect(f: (a: A) => Option): List;
/**
* _O(n)_ A version of `collect` which drops the remainder of the list starting
* with the first element for which the function `f` returns `None`.
*
* If the function `f` is a combination of a predicate `p: (a: A) => boolean`
* that determines whether or not a particular element should be kept in the
* resulting list, and a transformation `g: (a: A) => B`, then
* `xs.collectWhile(f)` is equivalent to `xs.takeWhile(p).map(f)`.
*
* @examples
*
* ```typescript
* > List('1', 'Foo', '3')
* > .collectWhile(s => Some(parseInt(x)).filterNot(Number.isNaN))
* // List(1)
* ```
*/
collectWhile(f: (a: A) => Option): List;
/**
* _O(n)_ Returns a tuple where the first element is a list 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
* > List(1, 2, 3, 4, 5, 6).partition(x => x % 2 === 0)
* // [List(2, 4, 6), List(1, 3, 5)]
* ```
*/
partition(p: (a: A) => a is B): [List, List];
partition(p: (a: A) => boolean): [List, List];
/**
* This method return 0, 1, 2 for when all values return either false, true,
* or mixed results for the given predicate.
*
* - 0: all values returned false
* - 1: all values returned true
* - 2: mixed results
*/
private partitionSingleSign;
private partitionImpl;
/**
* _O(n)_ Returns a tuple where the first element corresponds to the elements
* of the list returning `Left` by applying the function `f`, and the second
* one those that return `Right`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4, 5, 6).partitionWith(x =>
* > x % 2 === 0 ? Left(x % 2) : Right(String(x))
* > )
* // [List(1, 2, 3), List('1', '3', '5')]
* ```
*/
partitionWith(f: (a: A) => Either): [List, List];
/**
* _O(n)_ Returns an element at the index `idx`.
*
* @note This function is partial.
*
* @see getOption for a safe variant.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).get(0)
* // 1
*
* > List(1, 2, 3).get(2)
* // 3
*
* > List(1, 2, 3).get(3)
* // Uncaught Error: IndexOutOfBounds
*
* > List(1, 2, 3).get(-1)
* // Uncaught Error: IndexOutOfBounds
* ```
*/
get(idx: number): A;
/**
* Alias for `get`.
*/
'!!'(idx: number): A;
/**
* _O(n)_ Optionally returns an element at the index `idx`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).getOption(0)
* // Some(1)
*
* > List(1, 2, 3).getOption(2)
* // Some(3)
*
* > List(1, 2, 3).getOption(3)
* // None
*
* > List(1, 2, 3).getOption(-1)
* // None
* ```
*/
getOption(idx: number): Option;
/**
* Alias for `getOption`.
*/
'!?'(idx: number): Option;
/**
* _O(n)_ Replace an element at the index `idx` with the new value `x`.
*
* @note This is a partial function.
*
* @examples
*
* ```typescript
* > List('a', 'b', 'c').replaceAt(0, 'x')
* // List('x', 'b', 'c')
*
* > List('a', 'b', 'c').replaceAt(2, 'x')
* // List('a', 'b', 'x')
*
* > List('a', 'b', 'c').replaceAt(3, 'x')
* // Uncaught Error: IndexOutOfBounds
*
* > List('a', 'b', 'c').replaceAt(-1, 'x')
* // Uncaught Error: IndexOutOfBounds
* ```
*/
replaceAt(this: List, idx: number, x: A): List;
/**
* _O(n)_ Transforms an element at the index `idx` using the function `f`.
*
* @note This is a partial function.
*
* @examples
*
* ```typescript
* > List('a', 'b', 'c').modifyAt(0, c => c.toUpperCase())
* // List('A', 'b', 'c')
*
* > List('a', 'b', 'c').modifyAt(2, c => c.toUpperCase())
* // List('a', 'b', 'C')
*
* > List('a', 'b', 'c').modifyAt(3, c => c.toUpperCase())
* // Uncaught Error: IndexOutOfBounds
*
* > List('a', 'b', 'c').modifyAt(-1, c => c.toUpperCase())
* // Uncaught Error: IndexOutOfBounds
* ```
*/
modifyAt(this: List, idx: number, f: (a: A) => A): List;
/**
* _O(n)_ Inserts an element `x` at the index `idx` shifting the remainder of
* the list.
*
* @note This is a partial function.
*
* @examples
*
* ```typescript
* > List('a', 'b', 'c').insertAt(0, 'x')
* // List('x', 'a', 'b', 'c')
*
* > List('a', 'b', 'c').insertAt(2, 'x')
* // List('a', 'b', 'x', 'c')
*
* > List('a', 'b', 'c').insertAt(3, 'x')
* // List('a', 'b', 'c', 'x')
*
* > List('a', 'b', 'c').insertAt(4, 'x')
* // Uncaught Error: IndexOutOfBounds
*
* > List('a', 'b', 'c').insertAt(-1, 'x')
* // Uncaught Error: IndexOutOfBounds
* ```
*/
insertAt(this: List, idx: number, x: A): List;
/**
* _O(n)_ Removes an element `x` at the index `idx`.
*
* @note This is a partial function.
*
* @examples
*
* ```typescript
* > List('a', 'b', 'c').removeAt(0).toArray
* // ['b', 'c']
*
* > List('a', 'b', 'c').removeAt(2).toArray
* // ['a', 'b']
*
* > List('a', 'b', 'c').removeAt(3).toArray
* // Uncaught Error: IndexOutOfBounds
*
* > List('a', 'b', 'c').removeAt(-1).toArray
* // Uncaught Error: IndexOutOfBounds
* ```
*/
removeAt(idx: number): List;
/**
* _O(n)_ Returns the first index of on occurrence of the element `x` in the
* list, or `None` when it does not exist.
*
* @see elemIndices to get indices of _all_ occurrences of the element `x`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 1, 2, 3).elemIndex(1)
* // Some(0)
*
* > List(1, 2, 3).elemIndex(3)
* // Some(2)
*
* > List(1, 2, 3).elemIndex(0)
* // None
* ```
*/
elemIndex(this: List, x: A, E?: Eq): Option;
/**
* _O(n)_ Returns the indices of all occurrence of the element `x` in the list.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 1, 2, 3).elemIndices(1)
* // List(0, 3)
*
* > List(1, 2, 3).elemIndices(3)
* // List(2)
*
* > List(1, 2, 3).elemIndices(0)
* // List()
* ```
*/
elemIndices(this: List, x: A, E?: Eq): List;
/**
* _O(n)_ Returns index of the first element satisfying the predicate `p`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 1, 2, 3).findIndex(x => x > 1)
* // Some(1)
*
* > List(1, 2, 3).findIndex(x => x === 3)
* // Some(2)
*
* > List(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
* > List(1, 2, 3, 1, 2, 3).findIndices(x => x > 1)
* // List(1, 2, 4, 5)
*
* > List(1, 2, 3).findIndices(x => x === 3)
* // List(2)
*
* > List(1, 2, 3).findIndices(x => x > 20)
* // List()
* ```
*/
findIndices(p: (a: A) => boolean): List;
/**
* _O(n)_ Returns list with elements in reversed order.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).reverse
* // List(3, 2, 1)
*
* > List(42).reverse
* // List(42)
*
* > List.empty.reverse
* // List()
* ```
*/
get reverse(): List;
/**
* _O(n1)_ Appends all elements of the second list.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).concat(List(4, 5, 6))
* // List(1, 2, 3, 4, 5, 6)
* ```
*/
concat(this: List, that: List): List;
/**
* Alias for `concat`.
*/
'++'(this: List, that: List): List;
/**
* _O(n)_ Returns a new list by transforming each element using the function
* `f`.
*
* @examples
*
* ```typescript
* > List('a', 'b', 'c').map(x => x.toUpperCase())
* // List('A', 'B', 'C')
*
* > List.empty.map(() => { throw new Error(); })
* // List()
*
* > List.range(1, 3).map(x => x + 1)
* // List(2, 3, 4)
* ```
*/
map(f: (a: A) => B): List;
/**
* _O(m + n)_ Returns a list by transforming combination of elements from
* both lists using the function `f`.
*
* @examples
*
* ```typescript
* > List(1, 2).map2(List('a', 'b'), tupled)
* // List([1, 'a'], [1, 'b'], [2, 'a'], [2, 'b'])
* ```
*/
map2(that: List, f: (a: A, b: B) => C): List;
/**
* Lazy version of `map2`.
*
* @examples
*
* ```typescript
* > List(1, 2).map2Eval(Eval.now(List('a', 'b')), tupled).value
* // List([1, 'a'], [1, 'b'], [2, 'a'], [2, 'b'])
*
* > List.empty.map2Eval(Eval.bottom(), tupled).value
* // List()
* ```
*/
map2Eval(that: Eval>, f: (a: A, b: B) => C): Eval>;
/**
* Returns a new list by transforming each element using the function `f` and
* concatenating their results.
*
* @examples
*
* ```typescript
* > List(View.range(1), View.range(10), View.range(100))
* > .flatMap(xs => xs.take(3).toList)
* // List(1, 2, 3, 10, 11, 12, 100, 101, 102)
* ```
*/
flatMap(f: (a: A) => List): List;
/**
* Returns a new list concatenating its nested lists.
*
* `xss.flatten()` is equivalent to `xss.flatMap(id)`.
*/
flatten(this: List>): List;
/**
* _O(n)_ Create a new list by transforming each of its non-empty tails using
* a function `f`.
*
* @examples
*
* ```typescript
* > List('a', 'b', 'c').coflatMap(xs => xs.size)
* // List(3, 2, 1)
* ```
*/
coflatMap(f: (xs: List) => B): List;
/**
* _O(n)_ Inserts the given separator `sep` in between each of the elements of
* the list.
*
* @examples
*
* ```typescript
* > List('a', 'b', 'c').intersperse(',')
* // List('a', ',', 'b', ',', 'c')
* ```
*/
intersperse(this: List, sep: A): List;
/**
* _O(n * m)_ Transposes rows and columns of the list.
*
* @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
* > List(List(1, 2, 3), List(4, 5, 6)).transpose()
* // List(List(1, 4), List(2, 5), List(3, 6))
*
* > List(List(10, 11), List(20), List(), List(30, 31, 32)).transpose()
* // List(List(10, 20, 30), List(11, 31), List(32))
* ```
*/
transpose(this: List>): List>;
/**
* Returns a view of all subsequences.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).subsequences().toArray
* // [List(), List(1), List(2), List(1, 2), List(3), List(1, 3), List(2, 3), List(1, 2, 3)]
* ```
*/
subsequences(): View>;
private nonEmptySubsequences;
/**
* _O(min(n, m))_ Returns a list of pairs of corresponding elements of each
* list.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).zip(List('a', 'b', 'c'))
* // List([1, 'a'], [2, 'b'], [3, 'c'])
*
* > List(1, 2, 3).zip(List('a', 'b'))
* // List([1, 'a'], [2, 'b'])
*
* > List('a', 'b').zip(List(1, 2, 3))
* // List(['a', 1], ['b', 2])
*
* > List.empty.zip(List(1, 2, 3))
* // List()
*
* > List(1, 2, 3).zip(List.empty)
* // List()
* ```
*/
zip(that: List): List<[A, B]>;
/**
* Lazy version of `zip` that returns a `View`.
*/
zipView(that: List): 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
* > List(1, 2, 3).zipWith(List(4, 5, 6), (x, y) => x + y)
* // List(5, 7, 9)
* ```
*/
zipWith(ys: List, f: (a: A, b: B) => C): List;
/**
* Lazy version of `zipWith` that returns a `View`.
*/
zipWithView(that: List, f: (a: A, b: B) => C): View;
/**
* _O(n)_ Returns a list where each element is zipped with its index in the
* resulting list.
*
* @examples
*
* ```typescript
* > List('a', 'b', 'c').zipWithIndex
* // List(['a', 0], ['a', 1], ['a', 2])
*
* > List(1, 2, 3, 4, 5, 6).filter(x => x % 2 === 0).zipWithIndex.take(3)
* // List([2, 0], [4, 1], [6, 2])
*
* > List(1, 2, 3, 4, 5, 6).zipWithIndex.filter(([x]) => x % 2 === 0).take(3)
* // List([2, 1], [4, 3], [6, 5])
* ```
*/
get zipWithIndex(): List<[A, number]>;
/**
* _O(max(n, m))__ Version of `zip` that pads the shorter of the two lists
* with default values.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).zipAll(List('a', 'b', 'c'), 0, 'x')
* // List([1, 'a'], [2, 'b'], [3, 'c'])
*
* > List(1, 2, 3).zipAll(List('a', 'b'), 0, 'x')
* // List([1, 'a'], [2, 'b'], [3, 'x'])
*
* > List(1, 2).zipAll(List('a', 'b', 'c'), 0, 'x')
* // List([1, 'a'], [2, 'b'], [0, 'c'])
* ```
*/
zipAll(this: List, that: List, defaultX: A, defaultY: B): List<[A, B]>;
/**
* _O(max(m, n))_ A version of `zipAll` that takes a user-supplied zipping
* function `f`.
*/
zipAllWith(this: List, ys: List, defaultX: A, defaultY: B, f: (a: A, b: B) => C): List;
align(that: List): List>;
/**
* Version of `zip` working on three lists.
*/
zip3(ys: List, zs: List): List<[A, B, C]>;
/**
* Version of `zipView` working on three lists.
*/
zipView3(ys: List, zs: List): View<[A, B, C]>;
/**
* Version of `zipWith` working on three lists.
*/
zipWith3(ys: List, zs: List, f: (a: A, b: B, c: C) => D): List;
/**
* Version of `zipWithView` working on three lists.
*/
zipWithView3(ys: List, zs: List, f: (a: A, b: B, c: C) => D): View;
/**
* Version of `zipAll` working on three lists.
*/
zipAll3(ys: List, zs: List, defaultX: A, defaultY: B, defaultZ: C): List<[A, B, C]>;
/**
* Version of `zipAllWith` working on three lists.
*/
zipAllWith3(ys: List, zs: List, defaultX: A, defaultY: B, defaultZ: C, f: (a: A, b: B, c: C) => D): List;
/**
* _O(n)_ Transform a list of pairs into a list with its first components and
* a list with its second components.
*
* @examples
*
* ```typescript
* > List(['a', 1], ['b', 2], ['c', 3]).unzip()
* // [List('a', 'b', 'c'), List(1, 2, 3)]
* ```
*/
unzip(this: List): [List, List];
/**
* _O(n)_ Transform a list into a tuple of list by transforming contents of the
* original into tuples.
*
* @examples
*
* ```typescript
* > const quotRem = (x: number, y: number): [number, number] =>
* > [x / y | 0, x % y];
* > List(1, 2, 3, 4).unzipWith(x => quoteRem(x, 2))
* // [List(0, 1, 1, 2), List(1, 0, 1, 0)]
* ```
*/
unzipWith(f: (a: A) => readonly [B, C]): [List, List];
/**
* Version of `unzip` producing three lists.
*/
unzip3(this: List): [List, List, List];
/**
* Version of `unzipWith` producing three lists.
*/
unzipWith3(f: (a: A) => readonly [B, C, D]): [List, List, List];
private foldRight2;
private foldRight3;
/**
* _O(n)_ Returns a view of cumulative results reduced from left:
*
* `List(x1, x2, ...).scanLeft(z, f)` is equivalent to `List(z, f(z, x1), f(f(z, x1), x2), ...)`
*
*
* Relationship with `foldLeft`:
*
* `xs.scanLeft(z, f).last == xs.foldLeft(z, f)`
*
* @examples
*
* ```typescript
* > List(1, 2, 3).scanLeft(0, (z, x) => z + x)
* // List(0, 1, 3, 6)
*
* > List.empty.scanLeft(42, (z, x) => z + x)
* // List(42)
*
* > List.range(1, 5).scanLeft(100, (x, y) => x - y)
* // List(100, 99, 97, 94, 90)
* ```
*/
scanLeft(z: B, f: (b: B, a: A) => B): List;
/**
* Variant of `scanLeft` with no initial value.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).scanLeft1((z, x) => z + x)
* // List(1, 3, 6)
*
* > List.empty.scanLeft1((z, x) => z + x)
* // List()
*
* > List.range(1, 5).scanLeft1((x, y) => x - y)
* // List(1, -1, -4, -8)
*/
scanLeft1(this: List, f: (res: A, a: A) => A): List;
/**
* _O(n)_ Right-to-left dual of `scanLeft`.
*
* @see foldRight_ for strict version.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).scanRight_(0, (x, z) => x + z)
* // List(6, 5, 3, 0)
*
* > List.empty.scanRight_(42, (x, z) => x + z)
* // List(42)
*
* > List.range(1, 5).scanRight_(100, (x, z) => x - z)
* // List(98, -97, 99, -96, 100)
* ```
*/
scanRight(ez: Eval, f: (a: A, eb: Eval) => Eval): Eval>;
/**
* Version of `scanRight` with no initial value.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).scanRight1_((x, z) => x + z)
* // List(6, 5, 3)
*
* > List.empty.scanRight1_((x, z) => x + z)
* // List()
*
* > List.range(1, 5).scanRight1_((x, z) => x - z)
* // List(-2, 3, -1, 4)
* ```
*/
scanRight1(this: List, f: (a: A, er: Eval) => Eval): Eval>;
/**
* _O(n)_ Right-to-left dual of `scanLeft`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).scanRight_(0, (x, z) => x + z)
* // List(6, 5, 3, 0)
*
* > List.empty.scanRight_(42, (x, z) => x + z)
* // List(42)
*
* > List.range(1, 5).scanRight_(100, (x, z) => x - z)
* // List(98, -97, 99, -96, 100)
* ```
*/
scanRight_(z: B, f: (a: A, b: B) => B): List;
/**
* Version of `scanRight_` with no initial value.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).scanRight1_((x, z) => x + z)
* // List(6, 5, 3)
*
* > List.empty.scanRight1_((x, z) => x + z)
* // List()
*
* > List.range(1, 5).scanRight1_((x, z) => x - z)
* // List(-2, 3, -1, 4)
* ```
*/
scanRight1_(this: List, f: (a: A, res: A) => A): List;
/**
* _O(n^2)_ Removes duplicate elements from the list.
*
* @see distinctBy for the user supplied equality check.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4, 3, 2, 1, 2, 4, 3, 5).distinct()
* // List(1, 2, 3, 4, 5)
* ```
*/
distinct(this: List, E?: Eq): List;
/**
* Version of `distinct` function using a user-supplied equality check `eq`.
*/
distinctBy(eq: (x: A, y: A) => boolean): List;
private distinctPrim;
/**
* _O(n)_ Removes the first occurrence of `x` in the list.
*
* @see removeBy for the use-supplied comparison function.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 1, 2, 3).remove(1)
* // List(2, 3, 1, 2, 3)
*
* > List(2, 3).remove(1)
* // List(2, 3)
*
* > List().remove(1)
* // List()
* ```
*/
remove(this: List, x: A, E?: Eq): List;
/**
* Version of `remove` function using a user-supplied equality check `eq`.
*/
removeBy(this: List, x: A, eq: (x: A, y: A) => boolean): List;
private findToRemove;
/**
* _O(n * m)_ A non-associative collection difference. `difference` removes
* first occurrence of each element of `that` in the current list.
*
* `xs.concat(ys).difference(xs) === ys`
*
* @see differenceBy for the user-supplied comparison function.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 1, 2, 3).difference(List(2, 3))
* // List(1, 1, 2, 3)
*
* > List(1, 2, 3, 1, 2, 3).difference(List(1, 1, 2))
* // List(3, 2, 3)
*
* > List.range(1, 9).difference(List(1, 2, 3))
* // List(4, 5, 6, 7, 8)
* ```
*/
difference(this: List, that: List, E?: Eq): List;
/**
* Alias for `difference`.
*/
'\\'(this: List, that: List, E?: Eq): List;
/**
* Version of `difference` that uses user-supplied equality check `eq`.
*/
differenceBy(this: List, that: List, eq: (x: A, y: A) => boolean): List;
/**
* _O(max(n, m) * m)_ Creates a union of two lists.
*
* Duplicates and the elements from the first list are removed from the second
* one. But if there are duplicates in the original list, they are present in
* the result as well.
*
* @see unionBy for the user-supplied equality check.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).union(List(2, 3, 4))
* // List(1, 2, 3, 4)
*
* > List(1, 2, 3).union(List(1, 2, 3, 3, 4))
* // List(1, 2, 3, 4)
*
* > List(1, 1, 2, 3, 6).union(List(2, 3, 4))
* // List(1, 1, 2, 3, 6, 4)
*
* > List.range(1).union(List.range(1)).take(5)
* // List(1, 2, 3, 4, 5)
*
* > List(1, 2, 3).union(List.rage(1)).take(5)
* // List(1, 2, 3, 4, 5)
* ```
*/
union(this: List, that: List, E?: Eq): List;
/**
* Version of `union` that uses a user-supplied equality check `eq`.
*/
unionBy(this: List, that: List, eq: (x: A, y: A) => boolean): List;
private unionPrim;
/**
* _O(n * m)_ Creates an intersection of two lists. If the first list contains
* duplicates so does the second
*
* @see intersectBy for a user-supplied equality check.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4).intersect(List(2, 4, 6, 8))
* // List(2, 4)
*
* > List(1, 1, 2, 3).intersect(List(1, 2, 2, 5))
* // List(1, 1, 2)
* ```
*/
intersect(this: List, that: List, E?: Eq): List;
/**
* Version of `intersect` that uses user-supplied equality check `eq`.
*/
intersectBy(this: List, that: List, eq: (x: A, y: A) => boolean): List;
/**
* Apply `f` to each element of the view 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;
/**
* Apply a left-associative operator `f` to each element of the `List` reducing
* the list from left to right:
*
* ```typescript
* List(x1, x2, ..., xn) === f( ... f(f(z, x1), x2), ... xn)
* ```
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 4, 5).foldLeft(0, (x, y) => x + y)
* // 15
*
* > List.empty.foldLeft(42, (x, y) => x + y)
* // 42
* ```
*/
foldLeft(z: B, f: (b: B, a: A) => B): B;
/**
* Version of `foldLeft` without initial value and therefore it can be applied
* only to non-empty structures.
*
* @note This function is partial.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).foldLeft1((x, y) => x + y)
* // 6
*
* > List.empty.foldLeft1((x, y) => x + y)
* // Uncaught Error: List.foldLeft1: empty List
* ```
*/
foldLeft1(this: List, f: (res: A, x: A) => A): A;
/**
* Apply a right-associative operator `f` to each element of the `List`,
* reducing the list from right to left lazily:
*
* ```typescript
* List(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
* > List(false, true, false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // true
*
* > List(false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // false
*
* > List(true).foldRight(Eval.bottom(), (x, r) => x ? Eval.true : r).value
* // true
* ```
*/
foldRight(ez: Eval, f: (a: A, eb: Eval) => Eval): Eval;
/**
* 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
* > List(1, 2, 3).foldRight1((x, ey) => ey.map(y => x + y)).value
* // 6
*
* > List.empty.foldRight1((x, ey) => ey.map(y => x + y)).value
* // Uncaught Error: Nil.foldRight1
* ```
*/
foldRight1(this: List, f: (a: A, ea: 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: List, f: (x: A, res: A) => A): A;
/**
* 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
* > List(1, 3, 5).foldMap(Monoid.addition, id)
* // 9
*
* > List(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;
/**
* _O(n * log(n))_ Return sorted list.
*
* @see sortBy for user-supplied comparison function.
*
* @examples
*
* ```typescript
* > List(1, 6, 4, 3, 2, 5).sort()
* // List(1, 2, 3, 4, 5, 6)
* ```
*/
sort(this: List, O?: Ord): List;
/**
* _O(n * log(n))_ Return a list sorted by comparing results of function `f`
* applied to each of the element of the list.
*
* @examples
*
* ```typescript
* > List([2, 'world'], [4, '!'], [1, 'Hello']).sortOn(([fst, ]) => fst)
* // List([1, 'Hello'], [2, 'world'], [4, '!']])
* ```
*/
sortOn(f: (a: A) => B, O?: Ord): List;
/**
* Version of `sort` function using a user-supplied comparator `cmp`.
*/
sortBy(cmp: (l: A, r: A) => Compare): List;
/**
* _O(n)_ Inserts the element at the first position which is less, or equal to
* the inserted element. In particular, if the list is sorted to begin with,
* it will remain to be sorted.
*
* @see insertBy for user-supplied comparison function.
*
* @examples
*
* ```typescript
* > List(1, 2, 3, 5, 6, 7).insert(4)
* // List(1, 2, 3, 4, 5, 6, 7)
* ```
*/
insert(this: List, x: A, O?: Ord): List;
/**
* Version of `insert` function using a user-supplied comparator `cmp`.
*/
insertBy(this: List, x: A, cmp: (x: A, y: A) => Compare): List;
/**
* 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
* > List(1, 2, 3, 4).traverse(Option.Monad, Some)
* // Some(List(1, 2, 3, 4))
*
* > List(1, 2, 3, 4).traverse(Option.Monad, _ => None)
* // None
* ```
*/
traverse(G: Applicative, f: (a: A) => Kind): Kind]>;
private traverseImpl;
/**
* 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
* > List(Some(1), Some(2), Some(3)).sequence(Option.Monad)
* // Some(List(1, 2, 3))
*
* > List(Some(1), Some(2), None).sequence(Option.Monad)
* // None
* ```
*/
sequence(this: List>, 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;
/**
* Version of `traverse` which removes elements of the original list.
*
* @examples
*
* ```typescript
* > const m: Map = Map([1, 'one'], [3, 'three'])
* > List(1, 2, 3).traverseFilter(
* > Monad.Eval,
* > k => Eval.now(m.lookup(k)),
* > ).value
* // List('one', 'three')
* ```
*/
traverseFilter(G: Applicative, f: (a: A) => Kind]>): Kind]>;
private traverseFilterImpl;
private foldRightTraverse;
/**
* Given a list of strings, combine them into a single string separated by the
* separator `sep`.
*
* @examples
*
* ```typescript
* > List(1, 2, 3).join()
* // '1,2,3'
*
* > List('a', 'b', 'c').join(' ')
* // 'a b c'
*
* > List('a', 'b', 'c').join('')
* // 'abc'
* ```
*/
join(this: List, sep?: string): string;
toString(): string;
/**
* _O(1)_ Conditionally execute either `onNil` or `onCons` functions
* destructuring potentially empty list into its head and tail.
*/
abstract fold(onNil: () => B, onCons: (head: A, tail: List) => C): B | C;
equals(this: List, that: List, E?: Eq): boolean;
}
export declare class ListBuffer {
private first;
private last?;
private len;
private aliased;
get isEmpty(): boolean;
get nonEmpty(): boolean;
get toList(): List;
private ensureUnAliased;
private copyElems;
iterator(): Iterator;
addOne(x: A): this;
addAll(xs: List): this;
addAllIterable(it: Iterator): this;
static fromIterator(it: Iterator): ListBuffer;
}
/**
* @category Type Constructor
* @category Data
*/
export interface ListF extends TyK<[unknown]> {
[$type]: List>;
}
//# sourceMappingURL=list.d.ts.map