NonEmptyArrayModule

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

Summary

NameSignatureSynopsis
singletonNonEmptyArray.singleton valueBuilds an array of exactly one item.
ofArrayNonEmptyArray.ofArray valuesReturns the non-empty array, or None when the source is empty.
ofSeqNonEmptyArray.ofSeq valuesReturns the non-empty array, or None when the source is empty.
ofListNonEmptyArray.ofList valuesReturns the non-empty array, or None when the source is empty.
refinementNonEmptyArray.refinement ()Returns a refinement admitting any array with at least one item.
listRefinementNonEmptyArray.listRefinement ()Returns a refinement admitting a non-empty array from a list, which is the shape structured wire formats use.
createNonEmptyArray.create valuesAdmits a non-empty array, reporting the same failure the refinement does.
toArrayNonEmptyArray.toArray inputReturns a copy of the refined value as a standard array.
toListNonEmptyArray.toList inputReturns the refined value as a standard list.
toNonEmptyListNonEmptyArray.toNonEmptyList inputConverts to a non-empty list.
ofNonEmptyListNonEmptyArray.ofNonEmptyList inputConverts from a non-empty list.
headNonEmptyArray.head inputReturns the first item.
tailNonEmptyArray.tail inputReturns every item after the first.
lastNonEmptyArray.last inputReturns the final item.
lengthNonEmptyArray.length inputReturns the number of items as a plain int, matching Array.length.
mapNonEmptyArray.map mapping inputApplies a mapping to every item.
mapiNonEmptyArray.mapi mapping inputApplies an index-aware mapping to every item.
appendNonEmptyArray.append first secondConcatenates two non-empty arrays.
revNonEmptyArray.rev inputReverses the order of the items.
sortNonEmptyArray.sort inputSorts the items in ascending order.
sortByNonEmptyArray.sortBy projection inputSorts the items by a projected key.
sortWithNonEmptyArray.sortWith comparer inputSorts the items using an explicit comparison.
reduceNonEmptyArray.reduce reduction inputCombines every item with an associative operation.
foldNonEmptyArray.fold folder state inputFolds over the items from an explicit seed.
minNonEmptyArray.min inputReturns the smallest item.
maxNonEmptyArray.max inputReturns the largest item.
minByNonEmptyArray.minBy projection inputReturns the item with the smallest projected key.
maxByNonEmptyArray.maxBy projection inputReturns the item with the largest projected key.
filterNonEmptyArray.filter predicate inputFilters the items, returning a standard array because emptiness is possible.
tryFilterNonEmptyArray.tryFilter predicate inputFilters the items, returning None when nothing survives.
existsNonEmptyArray.exists predicate inputReturns whether any item satisfies the predicate.
forallNonEmptyArray.forall predicate inputReturns whether every item satisfies the predicate.
iterNonEmptyArray.iter action inputApplies an action to every item.
consToNonEmptyArray.consTo head inputPrepends an item to an already non-empty array.
indexedNonEmptyArray.indexed inputPairs every item with its index.
collectNonEmptyArray.collect mapping inputMaps each item to a non-empty array and concatenates the results.
concatNonEmptyArray.concat inputConcatenates a non-empty array of non-empty arrays.
sortDescendingNonEmptyArray.sortDescending inputSorts the items in descending order.
distinctNonEmptyArray.distinct inputRemoves duplicate items, preserving first-seen order.
zipNonEmptyArray.zip first secondPairs items positionally, truncating to the shorter input.
unzipNonEmptyArray.unzip inputSplits a non-empty array of pairs into a pair of non-empty arrays.
reduceBackNonEmptyArray.reduceBack reduction inputCombines every item from the right.
foldBackNonEmptyArray.foldBack folder input stateFolds over the items from the right.
partitionNonEmptyArray.partition predicate inputPartitions the items into matching and non-matching standard arrays.
containsNonEmptyArray.contains value inputReturns whether the array contains the item.
tryFindNonEmptyArray.tryFind predicate inputReturns the first matching item, if any.
toSeqNonEmptyArray.toSeq inputReturns the refined value as a sequence.
traverseResultNonEmptyArray.traverseResult mapping inputApplies a fallible mapping to every item, accumulating every failure rather than stopping at the first.
sequenceResultNonEmptyArray.sequenceResult inputCollects a non-empty array of results, accumulating every failure.
traverseOptionNonEmptyArray.traverseOption mapping inputApplies a mapping that may yield nothing, succeeding only when every item does.
sequenceOptionNonEmptyArray.sequenceOption inputCollects a non-empty array of options, succeeding only when every item is present.
groupByNonEmptyArray.groupBy projection inputGroups items by a key.
chunkBySizeNonEmptyArray.chunkBySize size inputSplits into consecutive runs of the given size, treating a size below one as one.
sumNonEmptyArray.sum inputAdds every item, matching Array.sum.
sumByNonEmptyArray.sumBy projection inputAdds a projection of every item, matching Array.sumBy.
averageNonEmptyArray.average inputAverages the items.
averageByNonEmptyArray.averageBy projection inputAverages a projection of the items.
countByNonEmptyArray.countBy projection inputCounts the items sharing each key.
scanNonEmptyArray.scan folder state inputRuns a fold and keeps every intermediate state, including the seed.
scanBackNonEmptyArray.scanBack folder input stateRuns a fold from the right and keeps every intermediate state.
tryFindBackNonEmptyArray.tryFindBack predicate inputReturns the last matching item, if any.
tryFindIndexNonEmptyArray.tryFindIndex predicate inputReturns the index of the first matching item, if any.
tryPickNonEmptyArray.tryPick chooser inputReturns the first item the chooser accepts, if any.
chooseNonEmptyArray.choose chooser inputKeeps the chosen items, returning a standard array because a chooser can reject every item.
tryChooseNonEmptyArray.tryChoose chooser inputKeeps the chosen items, returning None when nothing survives.
tryItemNonEmptyArray.tryItem index inputReturns the item at an index, or None when the index is out of range.
itemNonEmptyArray.item index inputReturns the item at an index, clamping the index into range.
truncateNonEmptyArray.truncate count inputKeeps at most the first count items, treating a count below one as one.
skipNonEmptyArray.skip count inputDrops the first count items, returning a standard array because skipping can consume everything.
pairwiseNonEmptyArray.pairwise inputPairs each item with its successor, returning a standard array — a single item yields none.
iteriNonEmptyArray.iteri action inputApplies an index-aware action to every item.
initNonEmptyArray.init count initialiserBuilds an array of count items from their indices, treating a count below one as one.
replicateNonEmptyArray.replicate count valueBuilds an array of count copies, treating a count below one as one.
sortByDescendingNonEmptyArray.sortByDescending projection inputSorts the items by a projected key, descending.
distinctByNonEmptyArray.distinctBy projection inputRemoves items sharing a projected key, keeping the first of each.
allPairsNonEmptyArray.allPairs first secondEvery pairing of an item from each array.
map2NonEmptyArray.map2 mapping first secondCombines items positionally, truncating to the shorter input.

singleton

NonEmptyArray.singleton value
Member
Builds an array of exactly one item.

Parameters

NameTypeDescription
value'a

Returns

NonEmptyArray<'a>

ofArray

NonEmptyArray.ofArray values
Member
Returns the non-empty array, or None when the source is empty.

Parameters

NameTypeDescription
values'value array

Returns

NonEmptyArray<'value> option

ofSeq

NonEmptyArray.ofSeq values
Member
Returns the non-empty array, or None when the source is empty.

Parameters

NameTypeDescription
values'a seq

Returns

NonEmptyArray<'a> option

ofList

NonEmptyArray.ofList values
Member
Returns the non-empty array, or None when the source is empty.

Parameters

NameTypeDescription
values'a list

Returns

NonEmptyArray<'a> option

refinement

NonEmptyArray.refinement ()
Member
Returns a refinement admitting any array with at least one item.

Parameters

NameTypeDescription
unit

Returns

Refinement<'value array, NonEmptyArray<'value>>

listRefinement

NonEmptyArray.listRefinement ()
Member
Returns a refinement admitting a non-empty array from a list, which is the shape structured wire formats use.

Parameters

NameTypeDescription
unit

Returns

Refinement<'value list, NonEmptyArray<'value>>

create

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

Parameters

NameTypeDescription
values'value seq

Returns

Result<NonEmptyArray<'value>, Violation>

toArray

NonEmptyArray.toArray input
Member
Returns a copy of the refined value as a standard array.

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

'value[]

toList

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

'value list

toNonEmptyList

NonEmptyArray.toNonEmptyList input
Member
Converts to a non-empty list.

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

NonEmptyList<'value>

ofNonEmptyList

NonEmptyArray.ofNonEmptyList input
Member
Converts from a non-empty list.

Parameters

NameTypeDescription
inputNonEmptyList<'value>

Returns

NonEmptyArray<'value>

head

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

'value

tail

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

'value[]

last

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

'value

length

NonEmptyArray.length input
Member
Returns the number of items as a plain int, matching Array.length.

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

int

map

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

Parameters

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

Returns

NonEmptyArray<'a>

mapi

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

Parameters

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

Returns

NonEmptyArray<'a>

append

NonEmptyArray.append first second
Member
Concatenates two non-empty arrays.

Parameters

NameTypeDescription
firstNonEmptyArray<'value>
secondNonEmptyArray<'value>

Returns

NonEmptyArray<'value>

rev

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

NonEmptyArray<'value>

sort

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

NonEmptyArray<'value>

sortBy

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

Parameters

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

Returns

NonEmptyArray<'value>

sortWith

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

Parameters

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

Returns

NonEmptyArray<'value>

reduce

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

Parameters

NameTypeDescription
reduction'value -> 'value -> 'value
inputNonEmptyArray<'value>

Returns

'value

fold

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

Parameters

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

Returns

'a

min

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

'value

max

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

'value

minBy

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

Parameters

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

Returns

'value

maxBy

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

Parameters

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

Returns

'value

filter

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

Parameters

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

Returns

'value[]

tryFilter

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

Parameters

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

Returns

NonEmptyArray<'a> option

exists

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

Parameters

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

Returns

bool

forall

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

Parameters

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

Returns

bool

iter

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

Parameters

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

Returns

unit

consTo

NonEmptyArray.consTo head input
Member
Prepends an item to an already non-empty array.

Parameters

NameTypeDescription
head'value
inputNonEmptyArray<'value>

Returns

NonEmptyArray<'value>

indexed

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

NonEmptyArray<int * 'value>

collect

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

Parameters

NameTypeDescription
mapping'value -> NonEmptyArray<'result>
inputNonEmptyArray<'value>

Returns

NonEmptyArray<'result>

concat

NonEmptyArray.concat input
Member
Concatenates a non-empty array of non-empty arrays.

Parameters

NameTypeDescription
inputNonEmptyArray<NonEmptyArray<'value>>

Returns

NonEmptyArray<'value>

sortDescending

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

NonEmptyArray<'value>

distinct

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

NonEmptyArray<'value>

zip

NonEmptyArray.zip first second
Member
Pairs items positionally, truncating to the shorter input. Total.

Parameters

NameTypeDescription
firstNonEmptyArray<'first>
secondNonEmptyArray<'second>

Returns

NonEmptyArray<'first * 'second>

unzip

NonEmptyArray.unzip input
Member
Splits a non-empty array of pairs into a pair of non-empty arrays.

Parameters

NameTypeDescription
inputNonEmptyArray<'first * 'second>

Returns

NonEmptyArray<'first> * NonEmptyArray<'second>

reduceBack

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

Parameters

NameTypeDescription
reduction'value -> 'value -> 'value
inputNonEmptyArray<'value>

Returns

'value

foldBack

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

Parameters

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

Returns

'a

partition

NonEmptyArray.partition predicate input
Member
Partitions the items into matching and non-matching standard arrays.

Parameters

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

Returns

'value[] * 'value[]

contains

NonEmptyArray.contains value input
Member
Returns whether the array contains the item.

Parameters

NameTypeDescription
value'value
inputNonEmptyArray<'value>

Returns

bool

tryFind

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

Parameters

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

Returns

'value option

toSeq

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

'value seq

traverseResult

NonEmptyArray.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>
inputNonEmptyArray<'value>

Returns

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

sequenceResult

NonEmptyArray.sequenceResult input
Member
Collects a non-empty array of results, accumulating every failure.

Parameters

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

Returns

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

traverseOption

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

Parameters

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

Returns

NonEmptyArray<'result> option

sequenceOption

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value option>

Returns

NonEmptyArray<'value> option

groupBy

NonEmptyArray.groupBy projection input
Member
Groups items by a key. Every group is non-empty by construction.

Parameters

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

Returns

Map<'a, NonEmptyArray<'value>>

chunkBySize

NonEmptyArray.chunkBySize size input
Member
Splits into consecutive runs of the given size, treating a size below one as one. Every chunk is non-empty.

Parameters

NameTypeDescription
sizeint
inputNonEmptyArray<'value>

Returns

NonEmptyArray<NonEmptyArray<'value>>

sum

NonEmptyArray.sum input
Member
Adds every item, matching Array.sum.

Parameters

NameTypeDescription
inputNonEmptyArray<^value>

Returns

^value

sumBy

NonEmptyArray.sumBy projection input
Member
Adds a projection of every item, matching Array.sumBy.

Parameters

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

Returns

^a

average

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

Parameters

NameTypeDescription
inputNonEmptyArray<^value>

Returns

^value

averageBy

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

Parameters

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

Returns

^a

countBy

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

Parameters

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

Returns

Map<'a, int>

scan

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

Parameters

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

Returns

NonEmptyArray<'a>

scanBack

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

Parameters

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

Returns

NonEmptyArray<'a>

tryFindBack

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

Parameters

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

Returns

'value option

tryFindIndex

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

Parameters

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

Returns

int option

tryPick

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

Parameters

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

Returns

'a option

choose

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

Parameters

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

Returns

'a[]

tryChoose

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

Parameters

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

Returns

NonEmptyArray<'b> option

tryItem

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

Parameters

NameTypeDescription
indexint
inputNonEmptyArray<'value>

Returns

'value option

item

NonEmptyArray.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
inputNonEmptyArray<'value>

Returns

'value

truncate

NonEmptyArray.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 Array.truncate 0 empties.

Parameters

NameTypeDescription
countint
inputNonEmptyArray<'value>

Returns

NonEmptyArray<'value>

skip

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

Parameters

NameTypeDescription
countint
inputNonEmptyArray<'value>

Returns

'value[]

pairwise

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

Parameters

NameTypeDescription
inputNonEmptyArray<'value>

Returns

('value * 'value)[]

iteri

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

Parameters

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

Returns

unit

init

NonEmptyArray.init count initialiser
Member
Builds an array of count items from their indices, treating a count below one as one. Total, where Array.init 0 yields an empty array.

Parameters

NameTypeDescription
countint
initialiserint -> 'a

Returns

NonEmptyArray<'a>

replicate

NonEmptyArray.replicate count value
Member
Builds an array of count copies, treating a count below one as one.

Parameters

NameTypeDescription
countint
value'a

Returns

NonEmptyArray<'a>

sortByDescending

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

Parameters

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

Returns

NonEmptyArray<'value>

distinctBy

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

Parameters

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

Returns

NonEmptyArray<'value>

allPairs

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

Parameters

NameTypeDescription
firstNonEmptyArray<'first>
secondNonEmptyArray<'second>

Returns

NonEmptyArray<'first * 'second>

map2

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

Parameters

NameTypeDescription
mapping'first -> 'second -> 'a
firstNonEmptyArray<'first>
secondNonEmptyArray<'second>

Returns

NonEmptyArray<'a>