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 { Foldable } from '../../foldable';
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 { Option } from '../option';
import { Set as OrdSet } from './set';
import { List } from './list';
import { LazyList } from './lazy-list';
import { Vector } from './vector';
import { Map } from './map';
import { Seq } from './seq';
/**
* Lazy, ordered sequence collection.
*
* View is a collection which operations are lazy, or non-strict. This means that
* the operations are not performed until the collection is effectively traversed
* (e.g., using `forEach`/`foldLeft`) or converted to a strict collection.
*
* This way we can effectively avoid creating intermediate copies of collections
* when performing chain of operations on a collection. For example, the
* following code should not create any intermediate copies of the `List`:
*
* ```typescript
* const xs: List = ...;
* const ys = xs.view
* .map(f)
* .filter(p)
* .map(h)
* .toList;
* ```
*
* To construct a view, use one of the constructor attached on the `View` class
* directly, or transform any of the fp4ts collections to a `View` using the
* an appropriate `.view` method.
*
* To construct a fully customized view, one can use view's dedicated `build`
* constructor. Views are [church-encoded](https://en.wikipedia.org/wiki/Church_encoding#Represent_the_list_using_right_fold)
* lists implemented by their `foldRight` method. This representation allows us
* to represent possibly infinite collections using finite memory and traverse
* them very efficiently because we don't need to allocate any additional memory
* to store contained data.
*
* @see _View
* @see _View.foldRight
*/
export type View = _View;
/**
*
* Construct a view by enumerating its contents.
*/
export declare const View: {
(...xs: readonly A[]): View;
/**
* Create a view by providing it's `foldRight` method.
*/
build(g: (ez: Eval, f: (a: A_1, eb: Eval) => Eval) => Eval): View;
/**
* Construct an empty `View` that does not contain any elements.
*/
empty: View;
cons(x: A_2, exs: View): View;
consEval(x: A_3, exs: Eval>): View;
/**
* Construct a singleton `View`.
*/
singleton(x: A_4): View;
/**
* Defer the definition of the `View`.
*
* This function is helpful when defining recursive views such as:
*
* ```typescript
* > const xs: View = View.defer(() => View.range(0, 2).concat(xs));
* > xs.take(20).toArray
* // [0, 1, 2, 0, 1, 2, 0, 1, 2, ...
* ```
*/
defer(thunk: () => View): View;
/**
* Create a possibly infinite stream of numbers starting at `from` lower bounds
* and ended by `to - 1`. Should one provide only the lower bound, the view
* returned by the function is going to be unbounded (or, infinite) as well.
*
* @examples
*
* ```typescript
* > View.range(0, 5).toArray
* // [0, 1, 2, 3, 4]
*
* > View.range(4).toArray
* // [4, 5, 6, 7, 8, 9, ...
* ```
*/
range(from: number, to?: number): View;
/**
* Creates an infinite stream of values where every element is an `a`.
*
* @examples
*
* ```typescript
* > View.repeat(42).take(10).toArray
* // [42, 42, 42, ...
* ```
*/
repeat(a: A_6): View;
/**
* Creates an infinite stream of repeated application of `f` on `a`:
*
* ```typescript
* View.iterate(x, f) == [x, f(x), f(f(x)), f(f(f(x))), ...
* ```
*
* @examples
*
* ```typescript
* > View.iterate(x, f).take(10).toArray
* // [x, f(x), f(f(x)), f(f(f(x))), ...
*
* > View.iterate(true, x => !x).take(5).toArray
* // [true, false, true, false, true]
*
* > View.iterate(0, x => x + 1).take(5).toArray
* // [0, 1, 2, 3, 4]
* ```
*/
iterate(a: A_7, f: (a: A_7) => A_7): View;
/**
* Creates a view of size `n` filled with elements `a`.
*
* @examples
*
* ```typescript
* > View.replicate(true, 0).toArray
* // []
*
* > View.replicate(true, -1).toArray
* // []
*
* > View.replicate(true, 5).toArray
* // [true, true, true, true, true]
* ```
*/
replicate(a: A_8, n: number): View;
/**
* Dual to `foldRight` function: while `foldRight` reduces the structure into
* a single result, `unfoldRight` build a (potentially infinite) view from the
* seed value `z` and a function `f`. The build ends once function `f` returns
* `None`.
*
* ```typescript
* const iterate = (a: A, f: (a: A) => A): View =>
* View.unfoldRight(a, a => Some([a, f(a)]);
* ```
*
* @examples
*
* ```typescript
* > View.unfoldRight(10, x => x > 0 ? Some([x, x - 1]) : None).toArray;
* // [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
* ```
*/
unfoldRight(z: B_1, f: (b: B_1) => Option<[A_9, B_1]>): View;
tailRecM_(a: A_10, f: (a: A_10) => View>): View;
/**
* Construct a view from an array.
*/
fromArray(xs: readonly A_11[]): View;
/**
* Construct a view from a `List`.
*/
fromList(xs: List): View;
/**
* Construct a view from a `LazyList`.
*/
fromLazyList(xs: LazyList): View;
/**
* Construct a view from a `strings`. The resulting view is a view of single
* character strings from the source string.
*
* @examples
*
* ```typescript
* > View.fromString('abc').toArray;
* // ['a', 'b', 'c']
* ```
*/
fromString(s: string): View;
/**
* Constructs a view by splitStringAt the provided `src` string using separator `sep`.
*
* @examples
*
* ```typescript
* > View.splitStringAt('a b c', ' ').toArray
* // ['a', 'b', 'c']
*
* > View.splitStringAt(' a b c', ' ').toArray
* // ['', 'a', 'b', 'c']
*
* > View.splitStringAt('a b c ', ' ').toArray
* // ['a', 'b', 'c', '']
*
* > View.splitStringAt('a b c', ' ').toArray
* // ['a', '', 'b', 'c', '']
*
* > View.splitStringAt('abc', '').toArray
* // ['a', 'b', 'c']
* ```
*/
splitStringAt(src: string, sep: string): View;
/**
* Construct a view from any `Iterable`.
*/
fromIterable(xs: Iterable): View;
/**
* Construct a view from an `Kind` using its `Foldable` instance.
*/
fromFoldable(F: Foldable): (fa: Kind) => View;
/**
* Construct a view from an `Iterator`.
*
* This constructor actually creates a `LazyList` from the iterator first, to
* ensure we can actually traverse the values yielded by the iterator more than
* once.
*/
fromIterator(iter: Iterator): View;
FunctorFilter: FunctorFilter;
MonoidK: MonoidK;
Alternative: Alternative;
Monad: Monad;
Foldable: Foldable;
TraversableFilter: TraversableFilter;
Unzip: Unzip;
};
export declare class _View {
/**
* Apply a right-associative operator `f` to each element of the `View`,
* reducing the view from right to left lazily:
*
* ```typescript
* View(x1, x2, ..., xn).foldRight(z, f) === f(x1, Eval.defer(() => f(x2, ... Eval.defer(() => f(xn, z), ... ))))
* ```
*
* @examples
*
* ```typescript
* > View(false, true, false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // true
*
* > View(false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // false
*
* > View.repeat(true).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // true
* ```
*
* #### Laziness and short-circuiting
*
* Although `foldRight` on infinite structures usually doesn't terminate, it
* may terminate in one of the following conditions:
*
* 1. the folding function `f` is short-circuiting
* 2. the folding function is lazy in its second argument
*
* This behavior is provided using the `Eval` data type from `@fp4ts/core`
* package.
*
* ##### Short-circuiting
*
* Should the tail of the computation not be needed, the computation on infinite
* structure terminates:
*
* ```typescript
* > View.repeat(true)
* > .foldRight(Eval.false, (x, r) => x ? Eval.true // short-circuit
* : r
* ).value
* // true
* ```
*
* But the following doesn't:
*
* ```
* > View.repeat(false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // *hangs*
* ```
* ##### Laziness
*
* Executing `foldRight` on an infinite structure terminates if the folding
* function `f` is lazy in its second argument. In other words, the `Eval`
* instance passed as the tail of the computation is not required to be
* used for the result:
*
* ```typescript
* > const add = (x: number) => (y: number): number => x + y
* > View.repeat(1)
* > .foldRight(
* > Eval.now(View.empty as View),
* > (i: number, eac: Eval>) =>
* > // we return immediate (or, strict) result within which we
* > // encapsule the tail of the infinite structure using `consEval`.
* > Eval.now(View.consEval(i, eac.map(ac => ac.map(add(3))))
* > )
* > ).value
* > .take(5) // execute eval
* // [1, 4, 7, 10, 13]
* ```
*/
readonly foldRight: (ez: Eval, f: (a: A, eb: Eval) => Eval) => Eval;
constructor(
/**
* Apply a right-associative operator `f` to each element of the `View`,
* reducing the view from right to left lazily:
*
* ```typescript
* View(x1, x2, ..., xn).foldRight(z, f) === f(x1, Eval.defer(() => f(x2, ... Eval.defer(() => f(xn, z), ... ))))
* ```
*
* @examples
*
* ```typescript
* > View(false, true, false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // true
*
* > View(false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // false
*
* > View.repeat(true).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // true
* ```
*
* #### Laziness and short-circuiting
*
* Although `foldRight` on infinite structures usually doesn't terminate, it
* may terminate in one of the following conditions:
*
* 1. the folding function `f` is short-circuiting
* 2. the folding function is lazy in its second argument
*
* This behavior is provided using the `Eval` data type from `@fp4ts/core`
* package.
*
* ##### Short-circuiting
*
* Should the tail of the computation not be needed, the computation on infinite
* structure terminates:
*
* ```typescript
* > View.repeat(true)
* > .foldRight(Eval.false, (x, r) => x ? Eval.true // short-circuit
* : r
* ).value
* // true
* ```
*
* But the following doesn't:
*
* ```
* > View.repeat(false).foldRight(Eval.false, (x, r) => x ? Eval.true : r).value
* // *hangs*
* ```
* ##### Laziness
*
* Executing `foldRight` on an infinite structure terminates if the folding
* function `f` is lazy in its second argument. In other words, the `Eval`
* instance passed as the tail of the computation is not required to be
* used for the result:
*
* ```typescript
* > const add = (x: number) => (y: number): number => x + y
* > View.repeat(1)
* > .foldRight(
* > Eval.now(View.empty as View),
* > (i: number, eac: Eval>) =>
* > // we return immediate (or, strict) result within which we
* > // encapsule the tail of the infinite structure using `consEval`.
* > Eval.now(View.consEval(i, eac.map(ac => ac.map(add(3))))
* > )
* > ).value
* > .take(5) // execute eval
* // [1, 4, 7, 10, 13]
* ```
*/
foldRight: (ez: Eval, f: (a: A, eb: Eval) => Eval) => Eval);
/**
* Extracts the first element of the view, which must be non-empty.
*
* `head` is a strict, short-circuiting operation that evaluates view until
* the first element is found.
*
* @note This function is partial.
*
* @see headOption for a safe variant
*
* @examples
*
* ```typescript
* > View(1, 2, 3).head
* // 1
*
* > View.range(1).head
* // 1
*
* > View.empty.head
* // Uncaught Error: View.head: empty View
* ```
*/
get head(): A;
/**
* Safe version of the `head` which optionally returns the first element of
* the view.
*
* `headOption` is a strict, short-circuiting operation that evaluates view
* until the first element is found.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).head
* // Some(1)
*
* > View.range(1).head
* // Some(1)
*
* > View.empty.head
* // None
* ```
*/
get headOption(): Option;
/**
* Extracts the elements of the view which come after the initial head. Equivalent
* to:
*
* ```typescript
* xs.tail == xs.drop(1)
* ```
*
* As such, it is safe to perform `tail` on empty views as well. `tail` is lazy
* and does not evaluate the view immediately.
*
* @examples
*
*```typescript
* > View(1, 2, 3).tail.toArray
* // [2, 3]
*
* > View(1).tail.toArray
* // []
*
* > View.empty.tail.toArray
* // []
* ```
*/
get tail(): View;
/**
* Extracts the last element of the view, which must be non-empty.
*
* `last` is a strict function requiring the entire view to be evaluated.
*
* @note This is a partial function.
*
* @see lastOption for a safe variant
*
* @examples
*
* ```typescript
* > View(1, 2, 3).last
* // 3
*
* > View(1).last
* // 1
*
* > View.empty.last
* // Uncaught Error: View.last: empty View
*
* > View.range(1).last
* // *hangs*
* ```
*/
get last(): A;
/**
* Optionally extracts the last element of the view.
*
* `last` is a strict function requiring the entire view to be evaluated.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).last
* // Some(3)
*
* > View(1).last
* // Some(1)
*
* > View.empty.last
* // None
*
* > View.range(1).last
* // *hangs*
* ```
*/
get lastOption(): Option;
/**
* Extract all elements of the view expect from the last one.
*
* `init` is lazy and does not require view to be evaluated immediately.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).init.toArray
* // [1, 2]
*
* > View(1).init.toArray
* // []
*
* > View.empty.init.toArray
* // []
* ```
*/
get init(): View;
/**
* Returns `true` if the view is empty, or `false` otherwise.
*
* `isEmpty` is a strict, short-circuiting function that requires evaluation
* of at least a single element.
*
* @examples
*
* ```typescript
* > View.empty.isEmpty
* // true
*
* > View(1).isEmpty
* // false
*
* > View.repeat(1).isEmpty
* // false
* ```
*/
get isEmpty(): boolean;
/**
* Returns `true` if the view is not empty, or `false` otherwise. An inverse of
* `isEmpty`:
*
* ```typescript
* xs.nonEmpty == !xs.isEmpty
* ```
*
* `nonEmpty` is a strict, short-circuiting function that requires evaluation
* of at least a single element.
*
* @examples
*
* ```typescript
* > View.empty.nonEmpty
* // false
*
* > View(1).nonEmpty
* // true
*
* > View.repeat(1).nonEmpty
* // true
* ```
*/
get nonEmpty(): boolean;
/**
* Returns the size of the view.
*
* `size` is a strict function that requires evaluation of the entire view.
*
* @examples
*
* ```typescript
* > View.empty.size
* // 0
*
* > View(1, 2, 3)
* // 3
*
* > View.repeat(1)
* // *hangs*
* ```
*/
get size(): number;
/**
* Converts the view into an array.
*/
get toArray(): A[];
/**
* Converts the view into a `List`.
*/
get toList(): List;
/**
* Converts the view into a `LazyList`. Since `LazyList` is a lazy collection,
* the view does not get evaluated until the elements are accessed.
*/
get toLazyList(): LazyList;
/**
* Converts the view into a `Vector`.
*/
get toVector(): Vector;
/**
* Converts the view into a `Seq`.
*/
get toSeq(): Seq;
/**
* Convert the view into an `Option`, returning `Some(head)` in case of an
* non-empty view, or `None` otherwise.
*
* `xs.toOption` is equivalent to `xs.headOption`.
*
* `headOption` is strict and short-circuiting, requiring evaluation of at least
* one element of the view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).toOption
* // Some(1)
*
* > View(1).toOption
* // Some(1)
*
* > View.repeat(1).toOption
* // Some(1)
*
* > View.empty.toOption
* // None
* ```
*/
get toOption(): Option;
/**
* Convert the view into an `Either`, returning `Right(head)` in case of an
* non-empty view, or `Left(left)` otherwise.
*
* `xs.toRight(left)` is equivalent to `xs.toOption.toRight(left)`
*
* `toRight` is strict and short-circuiting, requiring evaluation of at least
* one element of the view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).toRight(() => 42)
* // Right(1)
*
* > View(1).toRight(() => 42)
* // Right(1)
*
* > View.repeat(1).toRight(() => 42)
* // Right(1)
*
* > View.empty.toRight(() => 42)
* // Left(42)
* ```
*/
toRight(left: () => E): Either;
/**
* Convert the view into an `Either`, returning `Left(head)` in case of an
* non-empty view, or `Right(right)` otherwise.
*
* `xs.toLeft(right)` is equivalent to `xs.toOption.toLeft(right)`
*
* `toRight` is strict and short-circuiting, requiring evaluation of at least
* one element of the view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).toLeft(() => 42)
* // Left(1)
*
* > View(1).toLeft(() => 42)
* // Left(1)
*
* > View.repeat(1).toLeft(() => 42)
* // Left(1)
*
* > View.empty.toLeft(() => 42)
* // Right(42)
* ```
*/
toLeft(right: () => B): Either;
/**
* Converts the view into a `Set` using provided `Ord` instance, or
* `Ord.fromUniversalCompare()` if not provided.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).toSet()
* // Set(1, 2, 3)
*
* > View(1, 2, 2, 3, 3).toSet()
* // Set(1, 2, 3)
*
* > View.empty.toSet()
* // Set()
*
* > View.repeat(1).toSet()
* // *hangs*
* ```
*/
toSet(this: View, O?: Ord): OrdSet;
/**
* Converts the view of tuples `[K, V] into a `Map` using provided `Ord`
* instance, or `Ord.fromUniversalCompare()` if not provided.
*
* @examples
*
* ```typescript
* > View([1, 'a'], [2, 'b'], [3, 'c']).toMap()
* // Map([1, 'a'], [2, 'b'], [3, 'c'])
*
* > View([1, 'a'], [2, 'b'], [2, 'c'], [3, 'd'], [3, 'd']).toMap()
* // Map([1, 'a'], [2, 'c'], [3, 'd'])
*
* > View.empty.toMap()
* // Map()
*
* > View.repeat([1, 'a']).toMap()
* // *hangs*
* ```
*/
toMap(this: View<[K, V]>, O?: Ord): Map;
/**
* Returns an iterator of the elements of the view.
*
* @examples
*
* ```typescript
* > const it = View.empty.iterator
* > it.next()
* // { value: undefined, done: true }
*
* > const it = View(1, 2).iterator
* > it.next()
* // { value: 1, done: false }
* > it.next()
* // { value: 2, done: false }
* > it.next()
* // { value: undefined, done: true }
*
* > const it = View.repeat(1).iterator
* > it.next()
* // { value: 1, done: false }
* > it.next()
* // { value: 1, done: false }
* ```
*/
get iterator(): Iterator;
[Symbol.iterator](): Iterator;
/**
* Prepend an element `x` at the beginning the view.
*
* @examples
*
* ```typescript
* > View.empty.prepend(42).toArray
* // [42]
*
* > View(1, 2, 3).prepend(42).toArray
* // [42, 1, 2, 3]
*
* > View.repeat(1).prepend(42).take(3).toArray
* // [42, 1, 1]
* ```
*/
prepend(this: View, x: A): View;
/**
* Appends an element `x` at the end the view.
*
* @examples
*
* ```typescript
* > View.empty.append(42).toArray
* // [42]
*
* > View(1, 2, 3).append(42).toArray
* // [1, 2, 3, 42]
*
* > View.repeat(1).append(42).take(3).toArray
* // [1, 1, 1]
* ```
*/
append(this: View, x: A): View;
/**
* Ties a finite view into an infinite one.
*
* @note In case the initial view is empty, the view will never terminate.
*
* @examples
*
* ```typescript
* > View(1, 2).cycle().take(20).toArray
* // [1, 2, 1, 2, 1, ...
*
* > View.empty.cycle().take(20).toArray
* // *hangs*
* ```
*/
cycle(): View;
/**
* Returns `true` if for all elements of the view satisfy the predicate `p`,
* or `false` otherwise.
*
* ```typescript
* xs.all(p) === !xs.any(x => !p(x))
* ```
*
* `all` is strict and short-circuiting requiring evaluation of at least one
* element of the view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).all(() => true)
* // true
*
* > View(1, 2, 3).all(x => x < 3)
* // false
*
* > View.empty.all(() => false)
* // true
*
* > View.repeat(1).all(() => false)
* // false
*
* > View.repeat(1).all(() => false)
* // *hangs*
* ```
*/
all(p: (a: A) => a is B): this is View;
all(p: (a: A) => boolean): boolean;
/**
* Returns `true` if for at least one element of the view satisfy the predicate
* `p`, or `false` otherwise.
*
* ```typescript
* xs.any(p) == !xs.all(x => !p(x))
* ```
*
* `any` is strict and short-circuiting requiring evaluation of at least one
* element of the view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).any(() => true)
* // true
*
* > View(1, 2, 3).any(x => x < 10)
* // false
*
* > View.empty.any(() => true)
* // false
*
* > View.repeat(1).any(() => false)
* // false
*
* > View.repeat(1).any(() => true)
* // *hangs*
* ```
*/
any(p: (a: A) => boolean): boolean;
/**
* Returns number of elements of the view for which satisfy the predicate `p`.
*
* `count` is strict and requires evaluation of the entire view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).count(x => x >= 2)
* // 2
*
* > View.empty.count(x => true)
* // 0
*
* > View.repeat(1).count(x => false)
* // *hangs*
* ```
*/
count(p: (a: A) => boolean): number;
/**
* Returns max element of the non-empty view, using the provided `Ord`
* instance, or `Ord.fromUniversalCompare()` if not provided.
*
* `max` is strict and requires evaluation of the entire view.
*
* @note This function is partial.
*
* @see maxBy for user-supplied comparison function.
* @see maxOption for a safe variant.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).max()
* // 3
*
* > View.empty.max()
* // Uncaught Error: View.max: empty View
*
* > View.repeat(1).max()
* // *hangs*
* ```
*/
max(this: View, 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;
/**
* Optionally returns max element of the empty view, using the provided `Ord`
* instance, or `Ord.fromUniversalCompare()` if not provided.
*
* `maxOption` is strict and requires evaluation of the entire view.
*
* @see maxOptionBy for user-supplied comparison function.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).maxOption()
* // Some(3)
*
* > View.empty.maxOption()
* // None
*
* > View.repeat(1).maxOption()
* // *hangs*
* ```
*/
maxOption(this: View, O?: Ord): Option;
/**
* Version of `maxOption` function using a user-supplied comparator `cmp`.
*/
maxOptionBy(cmp: (l: A, r: A) => Compare): Option;
/**
* Returns min element of the non-empty view, using the provided `Ord`
* instance, or `Ord.fromUniversalCompare()` if not provided.
*
* `min` is strict and requires evaluation of the entire view.
*
* @note This function is partial.
*
* @see maxBy for user-supplied comparison function.
* @see minOption for a safe variant.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).min()
* // 1
*
* > View.empty.min()
* // Uncaught Error: View.min: empty View
*
* > View.repeat(1).min()
* // *hangs*
* ```
*/
min(this: View, 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(cmp: (l: A, r: A) => Compare): A;
/**
* Optionally returns min element of the empty view, using the provided `Ord`
* instance, or `Ord.fromUniversalCompare()` if not provided.
*
* `minOption` is strict and requires evaluation of the entire view.
*
* @see maxOptionBy for user-supplied comparison function.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).minOption()
* // Some(1)
*
* > View.empty.minOption()
* // None
*
* > View.repeat(1).minOption()
* // *hangs*
* ```
*/
minOption(this: View, O?: Ord): Option;
/**
* Version of `minOption` function using a user-supplied comparator `cmp`.
*/
minOptionBy(cmp: (l: A, r: A) => Compare): Option;
/**
* Returns sum of the elements of the view.
*
* `sum` is strict and requires evaluation of the entire view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4, 5).sum()
* // 15
*
* > View.empty.sum()
* // 0
*
* > View.repeat(1).sum()
* // *hangs*
* ```
*/
sum(this: View): number;
/**
* Returns product of the elements of the view.
*
* `product` is strict and requires evaluation of the entire view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).product()
* // 120
*
* > View.empty.product()
* // 1
*
* > View.repeat(1).product()
* // *hangs*
* ```
*/
product(this: View): number;
/**
* Returns prefix of length `n` of the given view if the size of the view is
* `< n`, otherwise the view itself.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4).take(3).toArray
* // [1, 2, 3]
*
* > View(1, 2).take(3).toArray
* // [1, 2]
*
* > View.empty.take(3).toArray
* // []
*
* > View(1, 2).take(-1).toArray
* // []
*
* > View.range(1).take(3).toArray
* // [1, 2, 3]
* ```
*/
take(n: number): View;
/**
* Returns suffix of the given view after the first `n` elements.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4).drop(3).toArray
* // [3]
*
* > View(1, 2).drop(3).toArray
* // [1, 2]
*
* > View.empty.drop(3).toArray
* // []
*
* > View(1, 2).drop(-1).toArray
* // [1, 2]
*
* > View.range(1).drop(3).take(5).toArray
* // [4, 5, 6, 7, 8]
* ```
*/
drop(n: number): View;
/**
* Combination of `drop` and `take`, equivalent to:
*
* ```typescript
* xs.slice(from, until) === xs.drop(from).take(until - from);
* ```
*/
slice(from: number, until: number): View;
/**
* Return a tuple where the first element if the view's prefix of size `n`
* and the second element is its remainder.
*
* ```typescript
* > View(1, 2, 3).splitAt(1).map(xs => xs.toArray)
* // [[1], [2, 3]]
* ```
*/
splitAt(n: number): [View, View];
/**
* Returns a longest prefix of elements satisfying the predicate `p`.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4, 1, 2, 3, 4).takeWhile(x => x < 3).toArray
* // [1, 2]
*
* > View(1, 2, 3).takeWhile(x => x < 5).toArray
* // [1, 2, 3]
*
* > View(1, 2, 3).takeWhile(x => x < 0).toArray
* // []
*
* > View.range(1).takeWhile(x => x < 3).toArray
* // [1, 2]
* ```
*/
takeWhile(p: (a: A) => a is B): View;
takeWhile(p: (a: A) => boolean): View;
/**
* Returns a remainder of the view after removing its longer prefix satisfying
* the predicate `p`.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4, 1, 2, 3, 4).dropWhile(x => x < 3).toArray
* // [3, 4, 1, 2, 3, 4]
*
* > View(1, 2, 3).dropWhile(x => x < 5).toArray
* // []
*
* > View(1, 2, 3).dropWhile(x => x < 0).toArray
* // [1, 2, 3]
*
* > View.range(1).dropWhile(x => x < 3).take(3).toArray
* // [3, 4, 5]
* ```
*/
dropWhile(p: (a: A) => boolean): View;
/**
* 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
* > View(1, 2, 3, 4, 1, 2, 3, 4)
* > .dropWhile(x => x < 3)
* > .map(xs => xs.toArray)
* // [[1, 2], [3, 4, 1, 2, 3, 4]]
*
* > View(1, 2, 3)
* > .dropWhile(_ => true)
* > .map(xs => xs.toArray)
* // [[1, 2, 3], []]
*
* > View(1, 2, 3)
* > .dropWhile(_ => false)
* > .map(xs => xs.toArray)
* // [[], [1, 2, 3]]
* ```
*/
span(p: (a: A) => a is B): [View, View];
span(p: (a: A) => boolean): [View, View];
/**
* Returns a view of of all possible prefixes of the view, shortest first.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).inits().map(xs => xs.toArray).toArray
* // [[], [1], [1, 2], [1, 2, 3]]
* ```
*/
inits(): View>;
/**
* Returns a view of of all possible suffixes of the view, longest first.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).inits().map(xs => xs.toArray).toArray
* // [[1, 2, 3], [2, 3], [3], []]
* ```
*/
tails(): View>;
/**
* Returns `true` if the view contains the element `a`, or `false` otherwise.
*
* `elem` is a strict, short-circuiting operation that requires evaluation of
* at least one element.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).elem(2)
* // true
*
* > View(1, 2, 3).elem(-1)
* // false
*
* > View([1, 2], [2, 3]).elem([1, 2], Eq.tuple(Eq.fromUniversalEquals(), Eq.fromUniversalEquals()))
* // true
*
* > View.range(1).elem(1)
* // true
*
* > View.range(1).elem(-1)
* // *hangs*
* ```
*/
elem(this: View, a: A, E?: Eq): boolean;
/**
* Negation of `elem`:
*
* ```typescript
* xs.notElem(x) === !xs.elem(x)
* ```
*/
notElem(this: View, a: A, E?: Eq): boolean;
/**
* Looks up a key in the view forming association list.
*
* `lookup` is a strict, short-circuiting operation that requires evaluation of
* at least one element.
*
* @examples
*
* ```typescript
* > View([1, 'one'], [2, 'two'], [3, 'three']).lookup(2)
* // Some('two')
*
* > View([1, 'one']).lookup(2)
* // None
*
* > View.empty.lookup(2)
* // None
*
* > View([1, 'one'], [2, 'two']).cycle().lookup(2)
* // Some(2)
*
* > View.cycle([1, 'one']).lookup(2)
* // *hangs*
* ```
*/
lookup(this: View, k: K, E?: Eq): Option;
/**
* Optionally returns the first element of the structure matching the
* predicate `p`.
*
* `find` is a strict, short-circuiting operation that requires evaluation of
* at least one element.
*
* @examples
*
* ```typescript
* > View.iterate(0, x => x + 5).find(x => x > 42)
* // Some(45)
*
* > View(1, 2, 3).find(x => x < 0)
* // None
*
* > View.iterate(0, x => x + 5).find(x => x < 0)
* // *hangs*
* ```
*/
find(p: (a: A) => a is B): Option;
find(p: (a: A) => boolean): Option;
/**
* Returns a view where all elements of the original view satisfy the predicate
* `p`.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4).filter(x => x % 2 === 0).toArray
* // [2, 4]
*
* > View.range(1).filter(x => x % 2 === 0).take(3).toArray
* // [2, 4, 6]
* ```
*/
filter(p: (a: A) => a is B): View;
filter(p: (a: A) => boolean): View;
/**
* Returns a view where all elements of the original view do not satisfy the
* predicate `p`.
*
* `xs.filterNot(p)` is equivalent to `xs.filter(x => !p(x))`
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4).filterNot(x => x % 2 === 0).toArray
* // [1, 3]
*
* > View.range(1).filterNot(x => x % 2 === 0).take(3).toArray
* // [1, 3, 5]
* ```
*/
filterNot(p: (a: A) => boolean): View;
/**
* A version of `map` which removes elements of the original view.
*
* 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 view, and a transformation `g: (a: A) => B`, then `xs.collect(f)`
* is equivalent to `xs.filter(p).map(f)`.
*
* @examples
*
* ```typescript
* > View('1', 'Foo', '3')
* > .collect(s => Some(parseInt(x)).filterNot(Number.isNaN))
* > .toArray
* // [1, 3]
* ```
*/
collect(f: (a: A) => Option): View;
/**
* A version of `collect` which drops the remainder of the view 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 view, and a transformation `g: (a: A) => B`, then
* `xs.collectWhile(f)` is equivalent to `xs.takeWhile(p).map(f)`.
*
* @examples
*
* ```typescript
* > View('1', 'Foo', '3')
* > .collectWhile(s => Some(parseInt(x)).filterNot(Number.isNaN))
* > .toArray
* // [1]
* ```
*/
collectWhile(f: (a: A) => Option): View;
/**
* Returns a tuple where the first element is a view 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
* > View(1, 2, 3, 4, 5, 6)
* > .partition(x => x % 2 === 0)
* > .map(xs => xs.toArray)
* // [[2, 4, 6], [1, 3, 5]]
* ```
*/
partition(p: (a: A) => a is B): [View, View];
partition(p: (a: A) => boolean): [View, View];
/**
* Returns an element at the index `idx`.
*
* `get` is a strict, short-circuiting operation that requires evaluation of
* at least on element.
*
* @note This function is partial.
*
* @see getOption for a safe variant.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).get(0)
* // 1
*
* > View(1, 2, 3).get(2)
* // 3
*
* > View(1, 2, 3).get(3)
* // Uncaught Error: IndexOutOfBounds
*
* > View(1, 2, 3).get(-1)
* // Uncaught Error: IndexOutOfBounds
* ```
*/
get(idx: number): A;
/**
* Optionally returns an element at the index `idx`.
*
* `getOption` is a strict, short-circuiting operation that requires
* evaluation of at least on element.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).getOption(0)
* // Some(1)
*
* > View(1, 2, 3).getOption(2)
* // Some(3)
*
* > View(1, 2, 3).getOption(3)
* // None
*
* > View(1, 2, 3).getOption(-1)
* // None
* ```
*/
getOption(idx: number): Option;
/**
* Replace an element at the index `idx` with the new value `x`.
*
* @note This is a partial function.
*
* @examples
*
* ```typescript
* > View('a', 'b', 'c').replaceAt(0, 'x').toArray
* // ['x', 'b', 'c']
*
* > View('a', 'b', 'c').replaceAt(2, 'x').toArray
* // ['a', 'b', 'x']
*
* > View('a', 'b', 'c').replaceAt(3, 'x').toArray
* // Uncaught Error: IndexOutOfBounds
*
* > View('a', 'b', 'c').replaceAt(-1, 'x').toArray
* // Uncaught Error: IndexOutOfBounds
* ```
*/
replaceAt(this: View, idx: number, x: A): View;
/**
* Transforms an element at the index `idx` using the function `f`.
*
* @note This is a partial function.
*
* @examples
*
* ```typescript
* > View('a', 'b', 'c').modifyAt(0, c => c.toUpperCase()).toArray
* // ['A', 'b', 'c']
*
* > View('a', 'b', 'c').modifyAt(2, c => c.toUpperCase()).toArray
* // ['a', 'b', 'C']
*
* > View('a', 'b', 'c').modifyAt(3, c => c.toUpperCase()).toArray
* // Uncaught Error: IndexOutOfBounds
*
* > View('a', 'b', 'c').modifyAt(-1, c => c.toUpperCase()).toArray
* // Uncaught Error: IndexOutOfBounds
* ```
*/
modifyAt(this: View, idx: number, f: (a: A) => A): View;
/**
* Inserts an element `x` at the index `idx` shifting the remainder of the
* view.
*
* @note This is a partial function.
*
* @examples
*
* ```typescript
* > View('a', 'b', 'c').insertAt(0, 'x').toArray
* // ['x', 'a', 'b', 'c']
*
* > View('a', 'b', 'c').insertAt(2, 'x').toArray
* // ['a', 'b', 'x', 'c']
*
* > View('a', 'b', 'c').insertAt(3, 'x').toArray
* // ['a', 'b', 'c', 'x']
*
* > View('a', 'b', 'c').insertAt(4, 'x').toArray
* // Uncaught Error: IndexOutOfBounds
*
* > View('a', 'b', 'c').insertAt(-1, 'x').toArray
* // Uncaught Error: IndexOutOfBounds
* ```
*/
insertAt(this: View, idx: number, x: A): View;
/**
* Removes an element `x` at the index `idx`.
*
* @note This is a partial function.
*
* @examples
*
* ```typescript
* > View('a', 'b', 'c').removeAt(0).toArray
* // ['b', 'c']
*
* > View('a', 'b', 'c').removeAt(2).toArray
* // ['a', 'b']
*
* > View('a', 'b', 'c').removeAt(3).toArray
* // Uncaught Error: IndexOutOfBounds
*
* > View('a', 'b', 'c').removeAt(-1).toArray
* // Uncaught Error: IndexOutOfBounds
* ```
*/
removeAt(idx: number): View;
/**
* Returns the first index of on occurrence of the element `x` in the view, or
* `None` when it does not exist.
*
* `elemIndex` is a strict, short-circuiting operation that requires evaluation
* of at least on element.
*
* @see elemIndices to get indices of _all_ occurrences of the element `x`.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 1, 2, 3).elemIndex(1)
* // Some(0)
*
* > View(1, 2, 3).elemIndex(3)
* // Some(2)
*
* > View(1, 2, 3).elemIndex(0)
* // None
*
* > View.range(1).elemIndex(40)
* // Some(39)
* ```
*/
elemIndex(this: View, x: A, E?: Eq): Option;
/**
* Returns the indices of all occurrence of the element `x` in the view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 1, 2, 3).elemIndices(1).toArray
* // [0, 3]
*
* > View(1, 2, 3).elemIndices(3).toArray
* // [2]
*
* > View(1, 2, 3).elemIndices(0).toArray
* // []
*
* > View.range(1).elemIndices(40).toArray
* // *hangs*
* ```
*/
elemIndices(this: View, x: A, E?: Eq): View;
/**
* Returns index of the first element satisfying the predicate `p`.
*
* `findIndex` is a strict, short-circuiting operation that requires evaluation
* of at least on element.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 1, 2, 3).findIndex(x => x > 1)
* // Some(1)
*
* > View(1, 2, 3).findIndex(x => x === 3)
* // Some(2)
*
* > View(1, 2, 3).findIndex(x => x > 20)
* // None
*
* > View.range(1).findIndex(x => x < 100)
* // *hangs*
* ```
*/
findIndex(p: (a: A) => boolean): Option;
/**
* Returns indices of all elements satisfying the predicate `p`.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 1, 2, 3).findIndices(x => x > 1).toArray
* // [1, 2, 4, 5]
*
* > View(1, 2, 3).findIndices(x => x === 3).toArray
* // [2]
*
* > View(1, 2, 3).findIndices(x => x > 20).toArray
* // []
*
* > View.range(1).findIndices(x => x < 100).toArray
* // *hangs*
* ```
*/
findIndices(p: (a: A) => boolean): View;
/**
* Returns view with elements in reversed order.
*
* `reverse` is a strict operation requiring evaluation of the entire view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).reverse.toArray
* // [3, 2, 1]
*
* > View(42).reverse.toArray
* // [42]
*
* > View.empty.reverse.toArray
* // []
*
* > View.range(1).reverse.toArray
* // *hangs**
* ```
*/
get reverse(): View;
/**
* Appends all elements of the second view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).concat(View(4, 5, 6)).toArray
* // [1, 2, 3, 4, 5, 6]
*
* > View(1, 2, 3).concat(View.range(4)).take(6).toArray
* // [1, 2, 3, 4, 5, 6]
* ```
*/
concat(this: View, that: View): View;
/**
* Version of `concat` lazy in its second argument.
*
* @see concat
*/
concatEval(this: View, that: Eval>): View;
/**
* Returns a new view by transforming each element using the function `f`.
*
* @examples
*
* ```typescript
* > View('a', 'b', 'c').map(x => x.toUpperCase()).toArray
* // ['A', 'B', 'C']
*
* > View.empty.map(() => { throw new Error(); }).toArray
* // []
*
* > View.range(1).map(x => x + 1).take(3).toArray
* // [2, 3, 4]
* ```
*/
map(f: (a: A) => B): View;
/**
* Returns a view by transforming combination of elements from both views using
* the function `f`.
*
* @examples
*
* ```typescript
* > View(1, 2).map2(View('a', 'b'), tupled).toArray
* // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
*
* > View.empty.map2(View.repeat(1), tupled).toArray
* // []
*
* > View.repeat(1).map2(View.empty, tupled).toArray
* // *hangs*
* ```
*/
map2(that: View, f: (a: A, b: B) => C): View;
/**
* Lazy version of `map2`.
*
* @examples
*
* ```typescript
* > View(1, 2).map2Eval(Eval.now(View('a', 'b')), tupled).value.toArray
* // [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
*
* > View.empty.map2Eval(Eval.bottom(), tupled).value.toArray
* // []
* ```
*/
map2Eval(that: Eval>, f: (a: A, b: B) => C): Eval>;
/**
* Returns a new view by transforming each element using the function `f` and
* concatenating their results.
*
* @examples
*
* ```typescript
* > View(View.range(1), View.range(10), View.range(100))
* > .flatMap(xs => xs.take(3))
* > .toArray
* // [1, 2, 3, 10, 11, 12, 100, 101, 102]
* ```
*/
flatMap(f: (a: A) => View): View;
/**
* Returns a new view concatenating its nested views.
*
* `xss.flatten()` is equivalent to `xss.flatMap(id)`.
*/
flatten(this: View>): View;
/**
* Inserts the given separator `sep` in between each of the elements of the view.
*
* @examples
*
* ```typescript
* > View('a', 'b', 'c').intersperse(',').toArray
* // ['a', ',', 'b', ',', 'c']
* ```
*/
intersperse(this: View, sep: A): View;
/**
* Returns a view of pairs of corresponding elements of each view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).zip(View('a', 'b', 'c')).toArray
* // [[1, 'a'], [2, 'b'], [3, 'c']]
*
* > View.range(1).zip(View('a', 'b')).toArray
* // [[1, 'a'], [2, 'b']]
*
* > View('a', 'b').zip(View.range(1)).toArray
* // [['a', 1], ['b', 2]]
*
* > View.empty.zip(View.range(1)).toArray
* // []
*
* > View.range(1).zip(View.empty).toArray
* // []
* ```
*/
zip(that: View): View<[A, B]>;
/**
* 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
* > View(1, 2, 3).zipWith(View(4, 5, 6), (x, y) => x + y).toArray
* // [5, 7, 9]
* ```
*/
zipWith(that: View, f: (a: A, b: B) => C): View;
/**
* Returns a view where each element is zipped with its index in the resulting
* sequence.
*
* `xs.zipWithIndex` is equivalent to `xs.zipWith(View.range(0))`
*
* @examples
*
* ```typescript
* > View('a', 'b', 'c').zipWithIndex.toArray
* // [['a', 0], ['a', 1], ['a', 2]]
*
* > View.range(1).filter(x => x % 2 === 0).zipWithIndex.take(3).toArray
* // [[2, 0], [4, 1], [6, 2]]
*
* > View.range(1).zipWithIndex.filter(([x]) => x % 2 === 0).take(3).toArray
* // [[2, 1], [4, 3], [6, 5]]
* ```
*/
get zipWithIndex(): View<[A, number]>;
/**
* Version of `zip` working on three views.
*/
zip3(bs: View, cs: View): View<[A, B, C]>;
/**
* Version of `zipWith` working on three views.
*/
zipWith3(bs: View, cs: View, f: (a: A, b: B, c: C) => D): View;
/**
* Transform a view of pairs into a view with its first components and a view
* with its second components.
*
* @examples
*
* ```typescript
* > View(['a', 1], ['b', 2], ['c', 3]).unzip().map(xs => xs.toArray)
* // [['a', 'b', 'c'], [1, 2, 3]]
* ```
*/
unzip(this: View): [View, View];
/**
* Version of `unzip` that works on tuples of three.
*/
unzip3(this: View): [View, View, View];
private foldRight2;
private zipPrevWith;
private foldRight3;
/**
* Returns a view of cumulative results reduced from left:
*
* `View(x1, x2, ...).scanLeft(z, f)` is equivalent to `[z, f(z, x1), f(f(z, x1), x2), ...]`
*
*
* Relationship with `foldLeft`:
*
* `xs.scanLeft(z, f).last == xs.foldLeft(z, f)`
*
* @examples
*
* ```typescript
* > View(1, 2, 3).scanLeft(0, (z, x) => z + x).toArray
* // [0, 1, 3, 6]
*
* > View.empty.scanLeft(42, (z, x) => z + x).toArray
* // [42]
*
* > View.range(1, 5).scanLeft(100, (x, y) => x - y).toArray
* // [100, 99, 97, 94, 90]
*
* > View.range(1).scanLeft(0, (x, y) => x + y).take(5).toArray
* // [0, 1, 3, 6, 10]
* ```
*/
scanLeft(z: B, f: (b: B, a: A) => B): View;
/**
* Right-to-left dual of `scanLeft`.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).scanRight(Eval.zero, (x, ez) => ez.map(z => x + z)).toArray
* // [6, 5, 3, 0]
*
* > View.empty.scanRight(Eval.now(42), (x, ez) => ez.map(z => x + z)).toArray
* // [42]
*
* > View.range(1, 5).scanRight(Eval.now(100), (x, ey) => ey.map(y => x - y)).toArray
* // [98, -97, 99, -96, 100]
*
* > View.range(1).scanRight(Eval.zero, (x, ez) => ez.map(z => x + z)).toArray
* // *hangs*
* ```
*/
scanRight(eb: Eval, f: (a: A, eb: Eval) => Eval): View;
/**
* Removes duplicate elements from the view.
*
* @see distinctBy for the user supplied equality check.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4, 3, 2, 1, 2, 4, 3, 5).distinct().toArray
* // [1, 2, 3, 4, 5]
* ```
*/
distinct(this: View, E?: Eq): View;
/**
* Version of `distinct` function using a user-supplied equality check `eq`.
*/
distinctBy(eq: (x: A, y: A) => boolean): View;
private distinctPrim;
/**
* Removes the first occurrence of `x` in the view.
*
* @see removeBy for the use-supplied comparison function.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 1, 2, 3).remove(1).toArray
* // [2, 3, 1, 2, 3]
*
* > View(2, 3).remove(1).toArray
* // [2, 3]
*
* > View.repeat(1).remove(1).take(3).toArray
* // [1, 1, 1]
* ```
*/
remove(this: View, x: A, E?: Eq): View;
/**
* Version of `remove` function using a user-supplied equality check `eq`.
*/
removeBy(x: A, eq: (x: A, y: A) => boolean): View;
/**
* A non-associative collection difference. `difference` removes first occurrence
* of each element of `that` in the current view.
*
* @see differenceBy for the user-supplied comparison function.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 1, 2, 3).difference(View(2, 3)).toArray
* // [1, 1, 2, 3]
*
* > View(1, 2, 3, 1, 2, 3).difference(View(1, 1, 2)).toArray
* // [3, 2, 3]
*
* > View.range(1).difference(View(1, 2, 3)).take(5).toArray
* // [4, 5, 6, 7, 8]
*
* > View(1, 2, 3, 4).difference(View.range(1)).take(5).toArray
* // *hangs*
* ```
*/
difference(this: View, that: View, E?: Eq): View;
/**
* Alias for `difference`.
*/
'\\'(this: View, that: View, E?: Eq): View;
/**
* Version of `difference` that uses user-supplied equality check `eq`.
*/
differenceBy(this: View, that: View, eq: (x: A, y: A) => boolean): View;
/**
* Creates a union of two views.
*
* Duplicates and the elements from the first view are removed from the second
* one. But if there are duplicates in the original view, they are present in
* the result as well.
*
* @see unionBy for the user-supplied equality check.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).union(View(2, 3, 4)).toArray
* // [1, 2, 3, 4]
*
* > View(1, 2, 3).union(View(1, 2, 3, 3, 4)).toArray
* // [1, 2, 3, 4]
*
* > View(1, 1, 2, 3, 6).union(View(2, 3, 4)).toArray
* // [1, 1, 2, 3, 6, 4]
*
* > View.range(1).union(View.range(1)).take(5).toArray
* // [1, 2, 3, 4, 5]
*
* > View(1, 2, 3).union(View.rage(1)).take(5).toArray
* // [1, 2, 3, 4, 5]
* ```
*/
union(this: View, that: View, E?: Eq): View;
private unionPrim;
/**
* Version of `union` that uses a user-supplied equality check `eq`.
*/
unionBy(this: View, that: View, eq: (x: A, y: A) => boolean): View;
/**
* Creates an intersection of two views. If the first list contains duplicates
* so does the second
*
* @see intersectBy for a user-supplied equality check.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4).intersect(View(2, 4, 6, 8)).toArray
* // [2, 4]
*
* > View(1, 1, 2, 3).intersect(View(1, 2, 2, 5)).toArray
* // [1, 1, 2]
* ```
*/
intersect(this: View, that: View, E?: Eq): View;
/**
* Version of `intersect` that uses user-supplied equality check `eq`.
*/
intersectBy(this: View, that: View, eq: (x: A, y: A) => boolean): View;
/**
* Apply `f` to each element of the view for its side-effect.
*
* `forEach` is a strict, _non_-short-circuiting function needing to evaluate
* the entire view.
*
* @examples
*
* ```typescript
* > let acc = 0;
* > View(1, 2, 3, 4, 5).forEach(x => acc += x)
* > acc
* // 15
*
* > let acc = 0;
* > View.range(1).forEach(x => acc += x)
* // *hangs*
* ```
*/
forEach(f: (a: A) => void): void;
/**
* Apply a left-associative operator `f` to each element of the `View` reducing
* the view from left to right:
*
* ```typescript
* View(x1, x2, ..., xn) === f( ... f(f(z, x1), x2), ... xn)
* ```
*
* `foldLeft` is a strict, _non_-short-circuiting function needing to evaluate
* the entire view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4, 5).foldLeft(0, (x, y) => x + y)
* // 15
*
* > View.empty.foldLeft(42, (x, y) => x + y)
* // 42
*
* > View.range(1).foldLeft(0, (x, y) => x + y)
* // *hangs*
* ```
*/
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
* > View(1, 2, 3).foldLeft1((x, y) => x + y)
* // 6
*
* > View.empty.foldLeft1((x, y) => x + y)
* // Uncaught Error: View.foldLeft1: empty View
*
* > View.range(1).foldLeft1((x, y) => x + y)
* // *hangs*
* ```
*/
foldLeft1(this: View, f: (acc: A, a: A) => A): A;
/**
* Version of `foldRight` without initial value and therefore it can be applied
* only to non-empty structures.
*
* @note This function is partial.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).foldRight1((x, ey) => ey.map(y => x + y)).value
* // 6
*
* > View.empty.foldRight1((x, ey) => ey.map(y => x + y)).value
* // Uncaught Error: View.foldRight1: empty View
*
* > View.range(1).foldRight1((x, ey) => ey.map(y => x + y)).value
* // *hangs*
* ```
*/
foldRight1(this: View, f: (a: A, eac: Eval) => Eval): Eval;
/**
* 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
* > View(1, 3, 5).foldMap(Monoid.addition, id)
* // 9
*
* > View(1, 3, 5).foldMap(Monoid.product, id)
* // 15
*
* > View.range(1).foldMap(Monoid.disjunction, x => x > 5)
* // true
* ```
*/
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` is a strict, _non_-short-circuiting function needing to evaluate
* the entire view.
*/
foldMapLeft(M: Monoid, f: (a: A) => M): M;
/**
* Transform each element of the structure into an applicative action and
* evaluate them left-to-right combining their result into a `View`.
*
* `traverse` uses `map2Eval` function of the provided applicative `G` allowing
* for short-circuiting.
*
* @see traverse_ for result-ignoring version.
* @see traverseList for a `List` producing traversal.
*
* @examples
*
* ```typescript
* > View(1, 2, 3, 4).traverse(Option.Monad, Some).map(xs => xs.toArray)
* // Some([1, 2, 3, 4])
*
* > View(1, 2, 3, 4).traverse(Option.Monad, _ => None).map(xs => xs.toArray)
* // None
*
* > View.range(1).traverse(Option.Monad, Some).map(xs => xs.toArray)
* // *hangs*
*
* > View.range(1).traverse(Option.Monad, _ => None).map(xs => xs.toArray)
* // None
* ```
*/
traverse(G: Applicative, f: (a: A) => Kind): Kind]>;
/**
* Version of `traverse` that instead of a `View`, produces a `List`. This is
* a function typically used when views are used for "fusion":
*
* ```typescript
* const xs: List = ...;
* const ys: Kind]> = xs.view
* .map(f)
* .filter(g)
* .traverseList(G, h);
* ```
*/
traverseList(G: Applicative, f: (a: A) => Kind): Kind]>;
/**
* 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.
* @see sequenceList for `List` producing version.
*
* @examples
*
* ```View
* > View(Some(1), Some(2), Some(3)).sequence(Option.Monad).map(xs => xs.toArray)
* // Some([1, 2, 3])
*
* > View(Some(1), Some(2), None).sequence(Option.Monad)
* // None
* ```
*/
sequence(this: View>, G: Applicative): Kind]>;
/**
* Version of `sequence` that instead of a `View`, produces a `List`. This
* version is typically used when views are used for "fusion":
*
* ```typescript
* const xs: List = ...;
* const ys: Kind]> = xs.view
* .filter(p)
* .map(f)
* .sequenceList(G);
* ```
*/
sequenceList(this: View>, G: Applicative): Kind]>;
/**
* Transform each element of the structure into an applicative action and
* evaluate them left-to-right ignoring the results.
*
* `traverseA` 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.
*
* `sequenceA` uses `map2Eval` function of the provided applicative `G` allowing
* for short-circuiting.
*/
sequence_(this: View>, G: Applicative): Kind;
/**
* Version of `traverse` which removes elements of the original view.
*
* @see traverseFilterList for `List` producing variant.
*
* @examples
*
* ```typescript
* > const m: Map = Map([1, 'one'], [3, 'three'])
* > View(1, 2, 3).traverseFilter(
* > Monad.Eval,
* > k => Eval.now(m.lookup(k)),
* > ).value.toArray
* // ['one', 'three']
* ```
*/
traverseFilter(G: Applicative, f: (a: A) => Kind]>): Kind]>;
/**
* Version of `traverseFilter` producing a `List`. This version is typically
* used when views are used for "fusion".
*/
traverseFilterList(G: Applicative, f: (a: A) => Kind]>): Kind]>;
/**
* Given a view of strings, combine them into a single string separated by the
* separator `sep`.
*
* `join` is a strict, _non_-short-circuiting function needing to evaluate
* the entire view.
*
* @examples
*
* ```typescript
* > View(1, 2, 3).join()
* // '1,2,3'
*
* > View('a', 'b', 'c').join(' ')
* // 'a b c'
*
* > View('a', 'b', 'c').join('')
* // 'abc'
* ```
*/
join(this: View, sep?: string): string;
toString(): string;
}
/**
* @category Type Constructor
* @category Data
*/
export interface ViewF extends TyK<[unknown]> {
[$type]: View>;
}
//# sourceMappingURL=view.d.ts.map