# Nel

## Definitions

`def ap(f: Nel[a -> b \ ef], l: Nel[a]): Nel[b] \ ef`

SourceApply every function from `f`

to every argument from `l`

and return a non-empty list with all results.
For `f = f1, f2, ...`

and `x = x1, x2, ...`

the results appear in the order
`f1(x1), f1(x2), ..., f2(x1), f2(x2), ...`

.

`def cons(x: a, l: Nel[a]): Nel[a]`

SourceReturns the non-empty list `l`

prefixed with the new element `x`

.

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

SourceReturns the number of elements in `l`

that satisfy the predicate `f`

.

`def dropWhile(f: a -> Bool \ ef, l: Nel[a]): List[a] \ ef`

SourceReturns `l`

without the longest prefix that satisfies the predicate `f`

.

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

SourceReturns an iterator over `l`

zipped with the indices of the elements.

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

SourceReturns `true`

if and only if at least one element in `l`

satisfies the predicate `f`

.

`def filter(f: a -> Bool, l: Nel[a]): List[a]`

SourceReturns a list of every element in `l`

that satisfies the predicate `f`

.

`def findLeft(f: a -> Bool \ ef, l: Nel[a]): Option[a] \ ef`

SourceOptionally returns the first element of `l`

that satisfies the predicate `f`

when searching from left to right.

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

SourceOptionally returns the first element of `l`

that satisfies the predicate `f`

when searching from right to left.

`def flatMap(f: a -> Nel[b] \ ef, l: Nel[a]): Nel[b] \ ef`

SourceReturns the result of applying `f`

to every element in `l`

and concatenating the results.

`def fold(l: Nel[a]): a`

SourceReturns the result of applying `combine`

to all the elements in `l`

, using `empty`

as the initial value.

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

SourceApplies `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)`

.

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

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

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

SourceApplies `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))...)`

.

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

SourceApplies `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.

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

SourceReturns `true`

if and only if all elements in `l`

satisfy the predicate `f`

.

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

SourceApplies `f`

to every element of `l`

along with that element's index.

`def intersperse(a: a, l: Nel[a]): Nel[a]`

SourceReturns `l`

with `a`

inserted between every two adjacent elements.

`def join(sep: String, l: Nel[a]): String`

SourceReturns the concatenation of the string representation
of each element in `l`

with `sep`

inserted between each element.

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

SourceReturns the concatenation of the string representation
of each element in `l`

according to `f`

with `sep`

inserted between each element.

`def map(f: a -> b \ ef, l: Nel[a]): Nel[b] \ ef`

SourceReturns the result of applying `f`

to every element in `l`

.

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

.

`def mapWithIndex(f: Int32 -> (a -> b \ ef), l: Nel[a]): Nel[b] \ ef`

SourceReturns 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) :: ...`

.

`def maximumBy(cmp: a -> (a -> Comparison), l: Nel[a]): a`

SourceFinds the largest element of `l`

according to the given comparator `cmp`

.

`def minimumBy(cmp: a -> (a -> Comparison), l: Nel[a]): a`

SourceFinds the smallest element of `l`

according to the given comparator `cmp`

.

`def permutations(l: Nel[a]): Nel[List[a]]`

SourceReturns all permutations of `l`

in lexicographical order by element indices in `l`

.

That is, `l`

is the first permutation and `reverse(l)`

is the last permutation.

`def reduce(l: Nel[a]): a`

SourceApplies `combine`

to all elements in `l`

until a single value is obtained.

`def reduceLeft(f: a -> (a -> a \ ef), l: Nel[a]): a \ ef`

SourceApplies `f`

to all elements in `l`

going from left to right until a single value `v`

is obtained.

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

`def reduceLeftTo(f: b -> (a -> b \ ef1), g: a -> b \ ef2, l: Nel[a]): b \ ef1 + ef2`

SourceLeft-associative reduction of a structure.
Applies `g`

to the initial element of `l`

and combines it
with the remainder of `l`

using `f`

going from left to right.

`def reduceRight(f: a -> (a -> a \ ef), l: Nel[a]): a \ ef`

SourceApplies `f`

to all elements in `l`

going from right to left until a single value `v`

is obtained.

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

`def reduceRightTo(f: a -> (b -> b \ ef1), g: a -> b \ ef2, l: Nel[a]): b \ ef1 + ef2`

SourceRight-associative reduction of a structure.
Applies `g`

to the initial element of `l`

and combines it
with the remainder of `l`

using `f`

going from right to left.

`def replace(from: { from = a }, to: { to = a }, l: Nel[a]): Nel[a]`

SourceReturns `l`

with every occurrence of `from`

replaced by `to`

.

`def sequence(l: Nel[m[a]]): m[Nel[a]]`

SourceReturns the result of applying the applicative mapping function `f`

to all the elements of the
non-empty list `l`

.

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

SourceOptionally returns the Nel `l`

shuffled using the Fisherâ€“Yates shuffle.

`def sort(l: Nel[a]): Nel[a]`

SourceSort the non-empty list `l`

so that elements are ordered from low to high according
to their `Order`

instance.

The sort is not stable, i.e., equal elements may appear in a different order than in the input `l`

.

The sort implementation is a Quicksort.

`def sortBy(f: a -> b, l: Nel[a]): Nel[a]`

SourceSort the non-empty list `l`

so that elements are ordered from low to high according
to the `Order`

instance for the values obtained by applying `f`

to each element.

The sort is not stable, i.e., equal elements may appear in a different order than in the input `l`

.

The sort implementation is a Quicksort.

`def sortWith(cmp: a -> (a -> Comparison), l: Nel[a]): Nel[a]`

SourceSort the non-empty list `l`

so that elements are ordered from low to high according
to the comparison function `cmp`

.

The sort is not stable, i.e., equal elements may appear in a different order than in the input `l`

.

The sort implementation is a Quicksort.

`def subsequences(l: Nel[a]): Nel[List[a]]`

SourceReturns all subsequences of `l`

in lexicographical order by element indices in `l`

.

That is, `l`

is the first subsequence and `Nil`

is the last subsequence.

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

SourceReturns the sum of all elements in the list `l`

according to the function `f`

.

`def takeWhile(f: a -> Bool \ ef, l: Nel[a]): List[a] \ ef`

SourceReturns the longest prefix of `l`

that satisfies the predicate `f`

.

`def toMapWith(f: a -> b, l: Nel[a]): Map[a, b]`

SourceReturns a map with elements of `l`

as keys and `f`

applied as values.

If `l`

contains multiple mappings with the same key, `toMapWith`

does not
make any guarantees about which mapping will be in the resulting map.

`def traverse(f: a -> m[b] \ ef, l: Nel[a]): m[Nel[b]] \ ef`

SourceReturns the result of running all the actions in the non-empty list `l`

.

`def unzip(l: Nel[(a, b)]): (Nel[a], Nel[b])`

SourceReturns a pair of non-empty lists, the first containing all first components in `l`

and the second containing all second components in `l`

.

`def zip(l1: Nel[a], l2: Nel[b]): Nel[(a, b)]`

SourceReturns a non-empty 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`

becomes depleted, then no further elements are added to the resulting list.

`def zipWith(f: a -> (b -> c \ ef), l1: Nel[a], l2: Nel[b]): Nel[c] \ ef`

SourceReturns a non-empty 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`

becomes depleted, then no further elements are added to the resulting list.

`def zipWithA(f: a -> (b -> m[c] \ ef), xs: Nel[a], ys: Nel[b]): m[Nel[c]] \ ef`

SourceGeneralize `zipWith`

to an applicative functor `f`

.

`def zipWithIndex(l: Nel[a]): Nel[(Int32, a)]`

SourceReturns a new non-empty list where each element `e`

is mapped to `(i, e)`

where `i`

is the index of `e`

.