# Nel

`case Nel(a, List[a])`

The NonEmptyList type.

### Instances

`instance Applicative[Nel]`

Source`instance Traversable[Nel]`

Source`instance UnorderedFoldable[Nel]`

Source## 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 append(l1: Nel[a], l2: Nel[a]): Nel[a]`

SourceReturns `l2`

appended to `l1`

.

`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 find(f: a -> Bool \ ef, l: Nel[a]): Option[a] \ ef`

SourceAlias for `findLeft`

.

`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 flatten(l: Nel[Nel[a]]): Nel[a]`

SourceReturns the concatenation of the elements in `l`

.

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

.

Returns 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 forEach(f: a -> Unit \ ef, l: Nel[a]): Unit \ ef`

SourceApplies `f`

to every element of `l`

.

`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 head(l: Nel[a]): a`

SourceReturns the first element of `l`

.

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

SourceReturns all elements in `l`

without the last element.

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

SourceReturns `l`

with `a`

inserted between every two adjacent elements.

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

SourceReturns an iterator over `l`

.

Returns 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 last(l: Nel[a]): a`

SourceReturns the last element of `l`

.

`def length(l: Nel[a]): Int32`

SourceReturns the length of `l`

.

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

.

Finds the largest element of `l`

according to the `Order`

on `a`

.

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

SourceFinds the largest element of `l`

according to the given comparator `cmp`

.

Returns `true`

if and only if `l`

contains the element `a`

.

Finds the smallest element of `l`

according to the `Order`

on `a`

.

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

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

Returns `l`

with every occurrence of `src`

replaced by `dst`

.

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

SourceReturns the reverse of `l`

.

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

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 singleton(x: a): Nel[a]`

SourceReturns a new non-empty list containing the single element `x`

.

Sort 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.

Sort 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 sum(l: Nel[Int32]): Int32`

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

.

`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 tail(l: Nel[a]): List[a]`

SourceReturns all elements in `l`

without the first element.

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

SourceReturns the longest prefix of `l`

that satisfies the predicate `f`

.

`def toArray(rc: Region[r], l: Nel[a]): Array[a, r] \ r`

SourceReturns `l`

as an array.

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

SourceReturns `l`

as a normal list.

Returns 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 toMutDeque(rc: Region[r], l: Nel[a]): MutDeque[a, r] \ r`

SourceReturns `l`

as a MutDeque.

Returns a string representation of the given non-empty list `l`

.

`def toVector(l: Nel[a]): Vector[a]`

SourceReturns `l`

as a vector.

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

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 with Applicative[m]`

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`

.