NonEmptyListModule

PackageReified.Refinements
Operations over lists that carry their non-emptiness in the type.

Summary

NameSignatureSynopsis
singletonNonEmptyList.singleton valueBuilds a list of exactly one item.
initNonEmptyList.init count initialiserBuilds a list of count items from their indices, treating a count below one as one.
replicateNonEmptyList.replicate count valueBuilds a list of count copies, treating a count below one as one.
consNonEmptyList.cons head tailPrepends an item to a standard list.
consToNonEmptyList.consTo head inputPrepends an item to an already non-empty list.
ofListNonEmptyList.ofList valuesReturns the non-empty list, or None when the source is empty.
ofSeqNonEmptyList.ofSeq valuesReturns the non-empty list, or None when the source is empty.
ofArrayNonEmptyList.ofArray valuesReturns the non-empty list, or None when the source is empty.
refinementNonEmptyList.refinement ()Returns a refinement admitting any list with at least one item.
createNonEmptyList.create valuesAdmits a non-empty list, reporting the same failure the refinement does.
toArrayNonEmptyList.toArray inputConverts to a non-empty array, preserving order.
toListNonEmptyList.toList inputReturns the refined value as a standard list.
toSeqNonEmptyList.toSeq inputReturns the refined value as a sequence.
headNonEmptyList.head inputReturns the first item.
tailNonEmptyList.tail inputReturns every item after the first.
lastNonEmptyList.last inputReturns the final item.
lengthNonEmptyList.length inputReturns the number of items as a plain int, matching List.length.
mapNonEmptyList.map mapping inputApplies a mapping to every item.
mapiNonEmptyList.mapi mapping inputApplies an index-aware mapping to every item.
indexedNonEmptyList.indexed inputPairs every item with its index.
appendNonEmptyList.append first secondConcatenates two non-empty lists.
appendListNonEmptyList.appendList first valuesAppends a standard list to a non-empty list.
collectNonEmptyList.collect mapping inputMaps each item to a non-empty list and concatenates the results.
concatNonEmptyList.concat inputConcatenates a non-empty list of non-empty lists.
revNonEmptyList.rev inputReverses the order of the items.
sortNonEmptyList.sort inputSorts the items in ascending order.
sortByNonEmptyList.sortBy projection inputSorts the items by a projected key.
sortWithNonEmptyList.sortWith comparer inputSorts the items using an explicit comparison.
sortDescendingNonEmptyList.sortDescending inputSorts the items in descending order.
sortByDescendingNonEmptyList.sortByDescending projection inputSorts the items by a projected key, descending.
distinctNonEmptyList.distinct inputRemoves duplicate items, preserving first-seen order.
distinctByNonEmptyList.distinctBy projection inputRemoves items sharing a projected key, keeping the first of each.
allPairsNonEmptyList.allPairs first secondEvery pairing of an item from each list.
zipNonEmptyList.zip first secondPairs items positionally, truncating to the shorter input.
map2NonEmptyList.map2 mapping first secondCombines items positionally, truncating to the shorter input.
unzipNonEmptyList.unzip inputSplits a non-empty list of pairs into a pair of non-empty lists.
reduceNonEmptyList.reduce reduction inputCombines every item with an associative operation.
reduceBackNonEmptyList.reduceBack reduction inputCombines every item from the right.
foldNonEmptyList.fold folder state inputFolds over the items from an explicit seed.
foldBackNonEmptyList.foldBack folder input stateFolds over the items from the right.
minNonEmptyList.min inputReturns the smallest item.
maxNonEmptyList.max inputReturns the largest item.
minByNonEmptyList.minBy projection inputReturns the item with the smallest projected key.
maxByNonEmptyList.maxBy projection inputReturns the item with the largest projected key.
sumNonEmptyList.sum inputAdds every item, matching List.sum.
sumByNonEmptyList.sumBy projection inputAdds a projection of every item, matching List.sumBy.
averageNonEmptyList.average inputAverages the items.
averageByNonEmptyList.averageBy projection inputAverages a projection of the items.
countByNonEmptyList.countBy projection inputCounts the items sharing each key.
scanNonEmptyList.scan folder state inputRuns a fold and keeps every intermediate state, including the seed.
scanBackNonEmptyList.scanBack folder input stateRuns a fold from the right and keeps every intermediate state.
filterNonEmptyList.filter predicate inputFilters the items, returning a standard list because emptiness is possible.
tryFilterNonEmptyList.tryFilter predicate inputFilters the items, returning None when nothing survives.
partitionNonEmptyList.partition predicate inputPartitions the items into matching and non-matching standard lists.
existsNonEmptyList.exists predicate inputReturns whether any item satisfies the predicate.
forallNonEmptyList.forall predicate inputReturns whether every item satisfies the predicate.
containsNonEmptyList.contains value inputReturns whether the list contains the item.
tryFindNonEmptyList.tryFind predicate inputReturns the first matching item, if any.
tryFindBackNonEmptyList.tryFindBack predicate inputReturns the last matching item, if any.
tryFindIndexNonEmptyList.tryFindIndex predicate inputReturns the index of the first matching item, if any.
tryPickNonEmptyList.tryPick chooser inputReturns the first item the chooser accepts, if any.
chooseNonEmptyList.choose chooser inputKeeps the chosen items, returning a standard list because a chooser can reject every item.
tryChooseNonEmptyList.tryChoose chooser inputKeeps the chosen items, returning None when nothing survives.
tryItemNonEmptyList.tryItem index inputReturns the item at an index, or None when the index is out of range.
itemNonEmptyList.item index inputReturns the item at an index, clamping the index into range.
truncateNonEmptyList.truncate count inputKeeps at most the first count items, treating a count below one as one.
skipNonEmptyList.skip count inputDrops the first count items, returning a standard list because skipping can consume everything.
pairwiseNonEmptyList.pairwise inputPairs each item with its successor, returning a standard list — a single item yields none.
iterNonEmptyList.iter action inputApplies an action to every item.
iteriNonEmptyList.iteri action inputApplies an index-aware action to every item.
groupByNonEmptyList.groupBy projection inputGroups items by a key.
chunkBySizeNonEmptyList.chunkBySize size inputSplits into consecutive runs of the given size.
traverseResultNonEmptyList.traverseResult mapping inputApplies a fallible mapping to every item, accumulating every failure rather than stopping at the first.
sequenceResultNonEmptyList.sequenceResult inputCollects a non-empty list of results, accumulating every failure.
traverseOptionNonEmptyList.traverseOption mapping inputApplies a mapping that may yield nothing, succeeding only when every item does.
sequenceOptionNonEmptyList.sequenceOption inputCollects a non-empty list of options, succeeding only when every item is present.

singleton

NonEmptyList.singleton value
Member
Builds a list of exactly one item.

Parameters

NameTypeDescription
value'a

Returns

NonEmptyList<'a>

init

NonEmptyList.init count initialiser
Member
Builds a list of count items from their indices, treating a count below one as one. Total, where List.init 0 yields an empty list.

Parameters

NameTypeDescription
countint
initialiserint -> 'a

Returns

NonEmptyList<'a>

replicate

NonEmptyList.replicate count value
Member
Builds a list of count copies, treating a count below one as one.

Parameters

NameTypeDescription
countint
value'a

Returns

NonEmptyList<'a>

cons

NonEmptyList.cons head tail
Member
Prepends an item to a standard list.

Parameters

NameTypeDescription
head'a
tail'a list

Returns

NonEmptyList<'a>

consTo

NonEmptyList.consTo head input
Member
Prepends an item to an already non-empty list.

Parameters

NameTypeDescription
head'value
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

ofList

NonEmptyList.ofList values
Member
Returns the non-empty list, or None when the source is empty.

Parameters

NameTypeDescription
values'a list

Returns

NonEmptyList<'a> option

ofSeq

NonEmptyList.ofSeq values
Member
Returns the non-empty list, or None when the source is empty.

Parameters

NameTypeDescription
values'a seq

Returns

NonEmptyList<'a> option

ofArray

NonEmptyList.ofArray values
Member
Returns the non-empty list, or None when the source is empty.

Parameters

NameTypeDescription
values'value array

Returns

NonEmptyList<'value> option

refinement

NonEmptyList.refinement ()
Member
Returns a refinement admitting any list with at least one item.

Parameters

NameTypeDescription
unit

Returns

Refinement<'value list, NonEmptyList<'value>>

create

NonEmptyList.create values
Member
Admits a non-empty list, reporting the same failure the refinement does.

Parameters

NameTypeDescription
values'value seq

Returns

Result<NonEmptyList<'value>, Violation>

toArray

NonEmptyList.toArray input
Member
Converts to a non-empty array, preserving order.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

'value[]

toList

NonEmptyList.toList input
Member
Returns the refined value as a standard list.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

'value list

toSeq

NonEmptyList.toSeq input
Member
Returns the refined value as a sequence.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

'value seq

head

NonEmptyList.head input
Member
Returns the first item. Total.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

'value

tail

NonEmptyList.tail input
Member
Returns every item after the first.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

'value list

last

NonEmptyList.last input
Member
Returns the final item. Total.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

'value

length

NonEmptyList.length input
Member
Returns the number of items as a plain int, matching List.length.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

int

map

NonEmptyList.map mapping input
Member
Applies a mapping to every item. Non-emptiness is preserved.

Parameters

NameTypeDescription
mapping'value -> 'a
inputNonEmptyList<'value>

Returns

NonEmptyList<'a>

mapi

NonEmptyList.mapi mapping input
Member
Applies an index-aware mapping to every item. Non-emptiness is preserved.

Parameters

NameTypeDescription
mappingint -> 'value -> 'a
inputNonEmptyList<'value>

Returns

NonEmptyList<'a>

indexed

NonEmptyList.indexed input
Member
Pairs every item with its index. Non-emptiness is preserved.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

NonEmptyList<int * 'value>

append

NonEmptyList.append first second
Member
Concatenates two non-empty lists.

Parameters

NameTypeDescription
firstNonEmptyList<'value>
secondNonEmptyList<'value>

Returns

NonEmptyList<'value>

appendList

NonEmptyList.appendList first values
Member
Appends a standard list to a non-empty list.

Parameters

NameTypeDescription
firstNonEmptyList<'value>
values'value list

Returns

NonEmptyList<'value>

collect

NonEmptyList.collect mapping input
Member
Maps each item to a non-empty list and concatenates the results.

Parameters

NameTypeDescription
mapping'value -> NonEmptyList<'result>
inputNonEmptyList<'value>

Returns

NonEmptyList<'result>

concat

NonEmptyList.concat input
Member
Concatenates a non-empty list of non-empty lists.

Parameters

NameTypeDescription
inputNonEmptyList<NonEmptyList<'value>>

Returns

NonEmptyList<'value>

rev

NonEmptyList.rev input
Member
Reverses the order of the items.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

sort

NonEmptyList.sort input
Member
Sorts the items in ascending order.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

sortBy

NonEmptyList.sortBy projection input
Member
Sorts the items by a projected key.

Parameters

NameTypeDescription
projection'value -> 'a
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

sortWith

NonEmptyList.sortWith comparer input
Member
Sorts the items using an explicit comparison.

Parameters

NameTypeDescription
comparer'value -> 'value -> int
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

sortDescending

NonEmptyList.sortDescending input
Member
Sorts the items in descending order.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

sortByDescending

NonEmptyList.sortByDescending projection input
Member
Sorts the items by a projected key, descending.

Parameters

NameTypeDescription
projection'value -> 'a
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

distinct

NonEmptyList.distinct input
Member
Removes duplicate items, preserving first-seen order. Non-emptiness is preserved.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

distinctBy

NonEmptyList.distinctBy projection input
Member
Removes items sharing a projected key, keeping the first of each. Non-emptiness is preserved.

Parameters

NameTypeDescription
projection'value -> 'a
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

allPairs

NonEmptyList.allPairs first second
Member
Every pairing of an item from each list. Non-emptiness is preserved.

Parameters

NameTypeDescription
firstNonEmptyList<'first>
secondNonEmptyList<'second>

Returns

NonEmptyList<'first * 'second>

zip

NonEmptyList.zip first second
Member
Pairs items positionally, truncating to the shorter input. Total — unlike List.zip, which raises when the lengths differ.

Parameters

NameTypeDescription
firstNonEmptyList<'first>
secondNonEmptyList<'second>

Returns

NonEmptyList<'first * 'second>

map2

NonEmptyList.map2 mapping first second
Member
Combines items positionally, truncating to the shorter input. Total — unlike List.map2, which raises when the lengths differ.

Parameters

NameTypeDescription
mapping'first -> 'second -> 'a
firstNonEmptyList<'first>
secondNonEmptyList<'second>

Returns

NonEmptyList<'a>

unzip

NonEmptyList.unzip input
Member
Splits a non-empty list of pairs into a pair of non-empty lists.

Parameters

NameTypeDescription
inputNonEmptyList<'first * 'second>

Returns

NonEmptyList<'first> * NonEmptyList<'second>

reduce

NonEmptyList.reduce reduction input
Member
Combines every item with an associative operation. Total — no seed required.

Parameters

NameTypeDescription
reduction'value -> 'value -> 'value
inputNonEmptyList<'value>

Returns

'value

reduceBack

NonEmptyList.reduceBack reduction input
Member
Combines every item from the right. Total — no seed required.

Parameters

NameTypeDescription
reduction'value -> 'value -> 'value
inputNonEmptyList<'value>

Returns

'value

fold

NonEmptyList.fold folder state input
Member
Folds over the items from an explicit seed.

Parameters

NameTypeDescription
folder'a -> 'value -> 'a
state'a
inputNonEmptyList<'value>

Returns

'a

foldBack

NonEmptyList.foldBack folder input state
Member
Folds over the items from the right.

Parameters

NameTypeDescription
folder'value -> 'a -> 'a
inputNonEmptyList<'value>
state'a

Returns

'a

min

NonEmptyList.min input
Member
Returns the smallest item. Total.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

'value

max

NonEmptyList.max input
Member
Returns the largest item. Total.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

'value

minBy

NonEmptyList.minBy projection input
Member
Returns the item with the smallest projected key. Total.

Parameters

NameTypeDescription
projection'value -> 'a
inputNonEmptyList<'value>

Returns

'value

maxBy

NonEmptyList.maxBy projection input
Member
Returns the item with the largest projected key. Total.

Parameters

NameTypeDescription
projection'value -> 'a
inputNonEmptyList<'value>

Returns

'value

sum

NonEmptyList.sum input
Member
Adds every item, matching List.sum.

Parameters

NameTypeDescription
inputNonEmptyList<^value>

Returns

^value

sumBy

NonEmptyList.sumBy projection input
Member
Adds a projection of every item, matching List.sumBy.

Parameters

NameTypeDescription
projection'value -> ^a
inputNonEmptyList<'value>

Returns

^a

average

NonEmptyList.average input
Member
Averages the items. Total — the divisor is the length, which is always at least one, so unlike List.average this cannot raise.

Parameters

NameTypeDescription
inputNonEmptyList<^value>

Returns

^value

averageBy

NonEmptyList.averageBy projection input
Member
Averages a projection of the items. Total, for the same reason as average.

Parameters

NameTypeDescription
projection'value -> ^a
inputNonEmptyList<'value>

Returns

^a

countBy

NonEmptyList.countBy projection input
Member
Counts the items sharing each key. Every count is at least one.

Parameters

NameTypeDescription
projection'value -> 'a
inputNonEmptyList<'value>

Returns

Map<'a, int>

scan

NonEmptyList.scan folder state input
Member
Runs a fold and keeps every intermediate state, including the seed.

Parameters

NameTypeDescription
folder'a -> 'value -> 'a
state'a
inputNonEmptyList<'value>

Returns

NonEmptyList<'a>

scanBack

NonEmptyList.scanBack folder input state
Member
Runs a fold from the right and keeps every intermediate state.

Parameters

NameTypeDescription
folder'value -> 'a -> 'a
inputNonEmptyList<'value>
state'a

Returns

NonEmptyList<'a>

filter

NonEmptyList.filter predicate input
Member
Filters the items, returning a standard list because emptiness is possible.

Parameters

NameTypeDescription
predicate'value -> bool
inputNonEmptyList<'value>

Returns

'value list

tryFilter

NonEmptyList.tryFilter predicate input
Member
Filters the items, returning None when nothing survives.

Parameters

NameTypeDescription
predicate'a -> bool
inputNonEmptyList<'a>

Returns

NonEmptyList<'a> option

partition

NonEmptyList.partition predicate input
Member
Partitions the items into matching and non-matching standard lists.

Parameters

NameTypeDescription
predicate'value -> bool
inputNonEmptyList<'value>

Returns

'value list * 'value list

exists

NonEmptyList.exists predicate input
Member
Returns whether any item satisfies the predicate.

Parameters

NameTypeDescription
predicate'value -> bool
inputNonEmptyList<'value>

Returns

bool

forall

NonEmptyList.forall predicate input
Member
Returns whether every item satisfies the predicate.

Parameters

NameTypeDescription
predicate'value -> bool
inputNonEmptyList<'value>

Returns

bool

contains

NonEmptyList.contains value input
Member
Returns whether the list contains the item.

Parameters

NameTypeDescription
value'value
inputNonEmptyList<'value>

Returns

bool

tryFind

NonEmptyList.tryFind predicate input
Member
Returns the first matching item, if any.

Parameters

NameTypeDescription
predicate'value -> bool
inputNonEmptyList<'value>

Returns

'value option

tryFindBack

NonEmptyList.tryFindBack predicate input
Member
Returns the last matching item, if any.

Parameters

NameTypeDescription
predicate'value -> bool
inputNonEmptyList<'value>

Returns

'value option

tryFindIndex

NonEmptyList.tryFindIndex predicate input
Member
Returns the index of the first matching item, if any.

Parameters

NameTypeDescription
predicate'value -> bool
inputNonEmptyList<'value>

Returns

int option

tryPick

NonEmptyList.tryPick chooser input
Member
Returns the first item the chooser accepts, if any.

Parameters

NameTypeDescription
chooser'value -> 'a option
inputNonEmptyList<'value>

Returns

'a option

choose

NonEmptyList.choose chooser input
Member
Keeps the chosen items, returning a standard list because a chooser can reject every item.

Parameters

NameTypeDescription
chooser'value -> 'a option
inputNonEmptyList<'value>

Returns

'a list

tryChoose

NonEmptyList.tryChoose chooser input
Member
Keeps the chosen items, returning None when nothing survives.

Parameters

NameTypeDescription
chooser'a -> 'b option
inputNonEmptyList<'a>

Returns

NonEmptyList<'b> option

tryItem

NonEmptyList.tryItem index input
Member
Returns the item at an index, or None when the index is out of range.

Parameters

NameTypeDescription
indexint
inputNonEmptyList<'value>

Returns

'value option

item

NonEmptyList.item index input
Member
Returns the item at an index, clamping the index into range. Total — index zero is always the head, so there is no empty case to report.

Parameters

NameTypeDescription
indexint
inputNonEmptyList<'value>

Returns

'value

truncate

NonEmptyList.truncate count input
Member
Keeps at most the first count items, treating a count below one as one. Total, and non-emptiness is preserved — where List.truncate 0 empties.

Parameters

NameTypeDescription
countint
inputNonEmptyList<'value>

Returns

NonEmptyList<'value>

skip

NonEmptyList.skip count input
Member
Drops the first count items, returning a standard list because skipping can consume everything. Total — a count past the end yields the empty list rather than raising the way List.skip does.

Parameters

NameTypeDescription
countint
inputNonEmptyList<'value>

Returns

'value list

pairwise

NonEmptyList.pairwise input
Member
Pairs each item with its successor, returning a standard list — a single item yields none.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

('value * 'value) list

iter

NonEmptyList.iter action input
Member
Applies an action to every item.

Parameters

NameTypeDescription
action'value -> unit
inputNonEmptyList<'value>

Returns

unit

iteri

NonEmptyList.iteri action input
Member
Applies an index-aware action to every item.

Parameters

NameTypeDescription
actionint -> 'value -> unit
inputNonEmptyList<'value>

Returns

unit

groupBy

NonEmptyList.groupBy projection input
Member
Groups items by a key. Every group is non-empty by construction — a group only exists because something fell into it — so the values keep their type rather than degrading to a list the caller has to re-check.

Parameters

NameTypeDescription
projection'value -> 'a
inputNonEmptyList<'value>

Returns

Map<'a, NonEmptyList<'value>>

chunkBySize

NonEmptyList.chunkBySize size input
Member
Splits into consecutive runs of the given size. Total: a size below one is treated as one, where List.chunkBySize raises, and both the outer list and every chunk stay non-empty.

Parameters

NameTypeDescription
sizeint
inputNonEmptyList<'value>

Returns

NonEmptyList<NonEmptyList<'value>>

traverseResult

NonEmptyList.traverseResult mapping input
Member
Applies a fallible mapping to every item, accumulating every failure rather than stopping at the first.

Parameters

NameTypeDescription
mapping'value -> Result<'result, 'failure list>
inputNonEmptyList<'value>

Returns

Result<NonEmptyList<'result>, 'failure list>

sequenceResult

NonEmptyList.sequenceResult input
Member
Collects a non-empty list of results, accumulating every failure.

Parameters

NameTypeDescription
inputNonEmptyList<Result<'value, 'failure list>>

Returns

Result<NonEmptyList<'value>, 'failure list>

traverseOption

NonEmptyList.traverseOption mapping input
Member
Applies a mapping that may yield nothing, succeeding only when every item does.

Parameters

NameTypeDescription
mapping'value -> 'result option
inputNonEmptyList<'value>

Returns

NonEmptyList<'result> option

sequenceOption

NonEmptyList.sequenceOption input
Member
Collects a non-empty list of options, succeeding only when every item is present.

Parameters

NameTypeDescription
inputNonEmptyList<'value option>

Returns

NonEmptyList<'value> option