# DelayList

`enum DelayList[a: Type] with Sendable`Source
`case ENil``case ECons(a, DelayList[a])``case LCons(a, Lazy[DelayList[a]])``case LList(Lazy[DelayList[a]])`

### Instances

`instance Applicative[DelayList]`Source
`instance Eq[DelayList[a]] with Eq[a]`Source
`instance Filterable[DelayList]`Source
`instance Foldable[DelayList]`Source
`instance Functor[DelayList]`Source
`instance Iterable[DelayList[a]]`Source
`instance Monad[DelayList]`Source
`instance MonadZero[DelayList]`Source
`instance Monoid[DelayList[a]]`Source
`instance Order[DelayList[a]] with Order[a]`Source
`instance SemiGroup[DelayList[a]]`Source
`instance Sendable[DelayList[a]] with Sendable[a]`Source
`instance ToString[DelayList[a]] with ToString[a]`Source
`instance Traversable[DelayList]`Source
`instance UnorderedFoldable[DelayList]`Source
`instance Witherable[DelayList]`Source

## Definitions

`@Experimental @LazyWhenPure `
`def ap(f: DelayList[a -> b \ ef], l: DelayList[a]): DelayList[b] \ ef`

Apply every function from `f` to every argument from `l` and return a list with all results. For `f = f1, f2, ...` and `l = x1, x2, ...` the results appear in the order `f1(x1), f1(x2), ..., f2(x1), f2(x2), ...`.

Whether the i-th function in `f` (`fi`) is applied eagerly or lazily depends on its purity:

• If `fi` is pure then it is applied lazily (i.e. the tail of `l` is not forced).
• If `fi` is impure then it is applied eagerly (i.e. the entire list `l` is forced).

Note that this implies that ALL functions in `f` must be pure to avoid forcing `l`.

`@Experimental @Lazy `
`def append(l1: DelayList[a], l2: DelayList[a]): DelayList[a]`

Returns `l2` appended to `l1`.

Does not force the tail of `l1`.

`@Experimental `
`def count(f: a -> Bool \ ef, l: DelayList[a]): Int32 \ ef`

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

Forces the entire list `l`.

`@Experimental @Lazy `
`def drop(n: Int32, l: DelayList[a]): DelayList[a]`

Returns `l` without the first `n` elements.

Returns `ENil` if `n > length(l)`. Returns `l` if `n < 1`.

Does not force the tail of `l`.

`@Experimental @LazyWhenPure `
`def dropWhile(f: a -> Bool \ ef, l: DelayList[a]): DelayList[a] \ ef`

Returns `l` without the longest prefix that satisfies the predicate `f`.

Whether `f` is applied eagerly or lazily depends on its purity:

• If `f` is pure then it is applied lazily (i.e. the tail is not forced).
• If `f` is impure then it is applied eagerly (i.e. the tail is forced until the first element that satisfies `f`).
`@Experimental `
`def empty(): DelayList[a]`

Returns an empty DelayList.

`def enumerator(rc: Region[r], l: DelayList[a]): Iterator[(Int32, a), r, r] \ r`

Returns an iterator over `l` zipped with the indices of the elements.

`@Experimental `
`def exists(f: a -> Bool \ ef, l: DelayList[a]): Bool \ ef`

Returns `true` if and only if at least one element in `l` satisfies the predicate `f`.

Returns `false` if `l` is empty.

Forces elements of `l` until the predicate `f` is satisfied.

`@Experimental @LazyWhenPure `
`def filter(f: a -> Bool \ ef, l: DelayList[a]): DelayList[a] \ ef`

Returns a `DelayList` with every element in `l` that satisfies the predicate `f`.

Whether `f` is applied eagerly or lazily depends on its purity:

• If `f` is pure then it is applied lazily (i.e. the tail is not forced).
• If `f` is impure then it is applied eagerly (i.e. the entire list `l` is forced).
`@Experimental @LazyWhenPure `
`def filterMap(f: a -> Option[b] \ ef, l: DelayList[a]): DelayList[b] \ ef`

Collects the results of applying the partial function `f` to every element in `l`.

Whether `f` is applied eagerly or lazily depends on its purity:

• If `f` is pure then it is applied lazily (i.e. the tail is not forced).
• If `f` is impure then it is applied eagerly (i.e. the entire list `l` is forced).
`@Experimental `
`def findLeft(f: a -> Bool \ ef, l: DelayList[a]): Option[a] \ ef`

Optionally returns the first element of `l` that satisfies the predicate `f` when searching from left to right.

Forces elements of `l` until the predicate `f` is satisfied.

`@Experimental `
`def findMap(f: a -> Option[b] \ ef, l: DelayList[a]): Option[b] \ ef`

Returns the first non-None result of applying the partial function `f` to each element of `l`.

Returns `None` if every element `f(x)` of `l` is `None`.

Forces elements of `l` until `f(x)` returns `Some(v)`.

`@Experimental `
`def findRight(f: a -> Bool \ ef, l: DelayList[a]): Option[a] \ ef`

Optionally returns the first element of `l` that satisfies the predicate `f` when searching from right to left.

Forces the entire list `l`.

`@Experimental @LazyWhenPure `
`def flatMap(f: a -> DelayList[b] \ ef, l: DelayList[a]): DelayList[b] \ ef`

Returns the result of applying `f` to every element in `l` and concatenating the results.

Whether `f` is applied eagerly or lazily depends on its purity:

• If `f` is pure then it is applied lazily (i.e. the tail is not forced).
• If `f` is impure then it is applied eagerly (i.e. the entire list `l` is forced).
`@Experimental @Lazy `
`def flatten(l: DelayList[DelayList[a]]): DelayList[a]`

Returns the concatenation of the elements in `l`.

Does not force the tail of `l`.

`@Experimental `
`def foldLeft(f: b -> (a -> b \ ef), s: b, l: DelayList[a]): b \ ef`

Applies `f` to a start value `s` and all elements in `l` going from left to right.

That is, the result is of the form: `f(...f(f(s, x1), x2)..., xn)`.

Forces the entire list `l`.

`def foldMap(f: a -> b \ ef, l: DelayList[a]): b \ ef with Monoid[b]`

Returns the result of mapping each element and combining the results.

`@Experimental `
`def foldRight(f: a -> (b -> b \ ef), s: b, l: DelayList[a]): b \ ef`

Applies `f` to a start value `s` and all elements in `l` going from right to left.

That is, the result is of the form: `f(x1, ...f(xn-1, f(xn, s))...)`.

Forces the entire list `l`.

`@Experimental `
`def foldRightWithCont(f: a -> ((Unit -> b \ ef) -> b \ ef), z: b, l: DelayList[a]): b \ ef`

Applies `f` to a start value `z` and all elements in `l` going from right to left.

That is, the result is of the form: `f(x1, ...f(xn-1, f(xn, z))...)`.

A `foldRightWithCont` allows early termination by not calling the continuation.

Calling the continuation forces the list `l`.

`@Experimental `
`def forAll(f: a -> Bool \ ef, l: DelayList[a]): Bool \ ef`

Returns `true` if and only if all elements in `l` satisfy the predicate `f`.

Returns `true` if `l` is empty.

Forces elements in `l` until the first element that does not satisfy the predicate `f` (inclusive).

`@Experimental `
`def forEach(f: a -> Unit \ ef, l: DelayList[a]): Unit \ ef`

Applies `f` to every element of `l`.

Forces the entire list `l`.

`@Experimental `
`def forEachWithIndex(f: Int32 -> (a -> Unit \ ef), l: DelayList[a]): Unit \ ef`

Applies `f` to every element of `l` along with that element's index.

Forces the entire list `l`.

`@Experimental `
`def head(l: DelayList[a]): Option[a]`

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

Returns `None` if `l` is empty.

Does not force the tail of `l`.

`@Experimental @Lazy `
`def intercalate(l1: DelayList[a], l2: DelayList[DelayList[a]]): DelayList[a]`

Returns the concatenation of the elements in `l2` with the elements of `l1` inserted between every two adjacent elements of `l2`.

That is, returns `l2.1 :: l1.1 ... l1.n :: l2.2 :: ... :: l2.n-1 :: l1.1 :: ... :: l1.n :: l2.n :: ENil`.

Does not force the tail of `l2`.

`@Experimental @Lazy `
`def intersperse(x: a, l: DelayList[a]): DelayList[a]`

Returns `l` with `x` inserted between every two adjacent elements.

Does not force the tail of `l`.

`@Experimental `
`def isEmpty(l: DelayList[a]): Bool`

Returns true if and only if `l` is the empty DelayList, i.e. `ENil`.

Does not force the tail of `l`.

`@Experimental @Lazy `
`def iterator(rc: Region[r], l: DelayList[a]): Iterator[a, r, r] \ r`

Returns `l` as an `Iterator`.

Does not force any elements of the list.

`@Experimental `
`def join(sep: String, l: DelayList[a]): String with ToString[a]`

Returns the concatenation of the string representation of each element in `l` with `sep` inserted between each element.

Forces the entire list `l`.

`@Experimental `
`def joinWith(f: a -> String \ ef, sep: String, l: DelayList[a]): String \ ef`

Returns the concatenation of the string representation of each element in `l` according to `f` with `sep` inserted between each element.

Forces the entire list `l`.

`@Experimental `
`def last(l: DelayList[a]): Option[a]`

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

Returns `None` if `l` is empty.

Forces the entire list `l`.

`@Experimental `
`def length(l: DelayList[a]): Int32`

Returns the length of `l`.

Forces the entire list `l`.

`@Experimental @LazyWhenPure `
`def map(f: a -> b \ ef, l: DelayList[a]): DelayList[b] \ ef`

Returns the result of applying `f` to every element in `l`.

Whether `f` is applied eagerly or lazily depends on its purity:

• If `f` is pure then it is applied lazily (i.e. the tail is not forced).
• If `f` is impure then it is applied eagerly (i.e. the entire list `l` is forced).
`@Experimental @LazyWhenPure `
`def mapWithIndex(f: Int32 -> (a -> b \ ef), l: DelayList[a]): DelayList[b] \ ef`

Returns the result of applying `f` to every element in `l` along with that element's index.

That is, the result is of the form: `f(x1, 0) :: f(x2, 1) :: ...`.

Whether `f` is applied eagerly or lazily depends on its purity:

• If `f` is pure then it is applied lazily (i.e. the tail is not forced).
• If `f` is impure then it is applied eagerly (i.e. the entire list `l` is forced).
`@Experimental `
`def maximum(l: DelayList[a]): Option[a] with Order[a]`

Optionally finds the largest element of `l` according to the `Order` on `a`.

Returns `None` if `l` is empty.

Forces the entire list `l`.

`@Experimental `
`def maximumBy(cmp: a -> (a -> Comparison), l: DelayList[a]): Option[a]`

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

Returns `None` if `l` is empty.

Forces the entire list `l`.

`@Experimental `
`def memberOf(x: a, l: DelayList[a]): Bool with Eq[a]`

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

Forces elements until `x` is found.

`@Experimental `
`def minimum(l: DelayList[a]): Option[a] with Order[a]`

Optionally finds the smallest element of `l` according to the `Order` on `a`.

Returns `None` if `l` is empty.

Forces the entire list `l`.

`@Experimental `
`def minimumBy(cmp: a -> (a -> Comparison), l: DelayList[a]): Option[a]`

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

Returns `None` if `l` is empty.

Forces the entire list `l`.

`@Experimental `
`def nonEmpty(l: DelayList[a]): Bool`

Returns true if and only if `l` is a non-empty DelayList.

Does not force the tail of `l`.

`@Experimental `
`def partition(f: a -> Bool \ ef, l: DelayList[a]): (DelayList[a], DelayList[a]) \ ef`

Returns a pair of lists `(l1, l2)` where: - `l1` contains all elements of `l` that satisfy the predicate `f`. - `l2` contains all elements of `l` that DO NOT satisfy the predicate `f`.

Forces the entire list `l`.

`@Experimental @Lazy `
`def range(b: Int32, e: Int32): DelayList[Int32]`

Returns a `DelayList` of all integers between `b` (inclusive) and `e` (exclusive).

Returns an empty `DelayList` if `b >= e`.

`@Experimental `
`def reduceLeft(f: a -> (a -> a \ ef), l: DelayList[a]): Option[a] \ ef`

Applies `f` to all elements in `l` going from left to right until a single value `v` is obtained. Returns `Some(v)`.

That is, the result is of the form: `Some(f(...f(f(x1, x2), x3)..., xn))`

Returns `None` if `l` is empty.

Forces the entire list `l`.

`@Experimental `
`def reduceRight(f: a -> (a -> a \ ef), l: DelayList[a]): Option[a] \ ef`

Applies `f` to all elements in `l` going from right to left until a single value `v` is obtained. Returns `Some(v)`.

That is, the result is of the form: `Some(f(x1, ...f(xn-2, f(xn-1, xn))...))`

Returns `None` if `l` is empty.

Forces the entire list `l`.

`@Experimental @Lazy `
`def repeat(x: a): DelayList[a]`

Returns an infinite DelayList of repeating `x`s.

`@Experimental @Lazy `
`def replace(src: { src = a }, dst: { dst = a }, l: DelayList[a]): DelayList[a] with Eq[a]`

Returns `l` with every occurrence of `src` replaced by `dst`.

Does not force the tail of `l`.

`@Experimental @Lazy `
`def reverse(l: DelayList[a]): DelayList[a]`

Reverses the list `l`.

Does not force the tail of `l`.

`@Experimental `
`def sequence(l: DelayList[m[a]]): m[DelayList[a]] with Applicative[m]`

Returns the result of running all the actions in the DelayList `l`.

`def shuffle(rnd: Random, l: DelayList[a]): DelayList[a] \ IO`

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

`@Experimental `
`def singleton(x: a): DelayList[a]`

Return the singleton list with element `x`.

`@Experimental @LazyWhenPure `
`def span(f: a -> Bool \ ef, l: DelayList[a]): (DelayList[a], DelayList[a]) \ ef`

Returns a pair of lists `(l1, l2)` where: - `l1` is the longest prefix of `l` that satisfies the predicate `f`. - `l2` is the remainder of `l`.

Whether `f` is applied eagerly or lazily depends on its purity:

• If `f` is pure then it is applied lazily (i.e. the tail is not forced).
• If `f` is impure then it is applied eagerly (i.e. the entire list `l` is forced).
`@Experimental @Lazy `
`def startFrom(n: Int32): DelayList[Int32]`

Returns an infinite sequence of integers starting from and including `n`.

`@Experimental `
`def sum(l: DelayList[Int32]): Int32`

Returns the sum of all elements in the DelayList `l`.

Forces the entire list `l`.

`@Experimental `
`def sumWith(f: a -> Int32 \ ef, l: DelayList[a]): Int32 \ ef`

Returns the sum of all elements in the DelayList `l` according to the function `f`.

Forces the entire list `l`.

`@Experimental @Lazy `
`def tail(l: DelayList[a]): DelayList[a]`

Returns `l` without the first element.

Does not force the tail of `l`.

`@Experimental @Lazy `
`def take(n: Int32, l: DelayList[a]): DelayList[a]`

Returns the first `n` elements of `l`.

Does not force the tail of `l`.

`@Experimental @LazyWhenPure `
`def takeWhile(f: a -> Bool \ ef, l: DelayList[a]): DelayList[a] \ ef`

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

Whether `f` is applied eagerly or lazily depends on its purity:

• If `f` is pure then it is applied lazily (i.e. the tail is not forced).
• If `f` is impure then it is applied eagerly (i.e. the tail is forced until the first element that satisfies `f`).
`@Experimental `
`def toArray(rc: Region[r], l: DelayList[a]): Array[a, r] \ r`

Returns `l` as an `Array`.

Forces the entire list `l`.

`@Experimental `
`def toList(l: DelayList[a]): List[a]`

Returns `l` as a `List`.

Forces the entire list `l`.

`@Experimental `
`def toMap(l: DelayList[(a, b)]): Map[a, b] with Order[a]`

Returns the association list `l` as a map.

If `l` contains multiple mappings with the same key, `toMap` does not make any guarantees about which mapping will be in the resulting map.

Forces the entire list `l`.

`def toMutDeque(rc: Region[r], l: DelayList[a]): MutDeque[a, r] \ r`

Returns `l` as a MutDeque.

`@Experimental `
`def toMutList(rc: Region[r], l: DelayList[a]): MutList[a, r] \ r`

Returns `l` as a `List`.

Forces the entire list `l`.

`@Experimental `
`def toSet(l: DelayList[a]): Set[a] with Order[a]`

Returns `l` as a `Set`.

Forces the entire list `l`.

`@Experimental `
`def toString(l: DelayList[a]): String with ToString[a]`

Returns a string representation of `l`.

Forces the entire list `l`.

`@Experimental `
`def toVector(l: DelayList[a]): Vector[a]`

Returns `l` as a Vector.

Forces the entire list `l`.

`@Experimental `
`def traverse(f: a -> m[b] \ ef, l: DelayList[a]): m[DelayList[b]] \ ef with Applicative[m]`

Returns the result of applying the applicative mapping function `f` to all the elements of the DelayList `l`.

`@Experimental @Lazy `
`def zip(l1: DelayList[a], l2: DelayList[b]): DelayList[(a, b)]`

Returns a list where the element at index `i` is `(a, b)` where `a` is the element at index `i` in `l1` and `b` is the element at index `i` in `l2`.

If either `l1` or `l2` is depleted, then no further elements are added to the resulting list.

Does not force the tail of either `l1` or `l2`.

`@Experimental @LazyWhenPure `
`def zipWith(f: a -> (b -> c \ ef), l1: DelayList[a], l2: DelayList[b]): DelayList[c] \ ef`

Returns a list where the element at index `i` is `f(a, b)` where `a` is the element at index `i` in `l1` and `b` is the element at index `i` in `l2`.

If either `l1` or `l2` is depleted, then no further elements are added to the resulting list.

Whether `f` is applied eagerly or lazily depends on its purity:

• If `f` is pure then it is applied lazily (i.e. the tails are not forced).
• If `f` is impure then it is applied eagerly (i.e. both lists `l1` and `l2` are forced).
`def zipWithIndex(l: DelayList[a]): DelayList[(Int32, a)]`

Returns a `DelayList` where each element `e` is mapped to `(i, e)` where `i` is the index of `e`.

Does not force the tail of `l`.