NonEmptyArrayModule
PackageReified.Refinements
Operations over arrays that carry their non-emptiness in the type.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| singleton | NonEmptyArray.singleton value | Builds an array of exactly one item. |
| ofArray | NonEmptyArray.ofArray values | Returns the non-empty array, or None when the source is empty. |
| ofSeq | NonEmptyArray.ofSeq values | Returns the non-empty array, or None when the source is empty. |
| ofList | NonEmptyArray.ofList values | Returns the non-empty array, or None when the source is empty. |
| refinement | NonEmptyArray.refinement () | Returns a refinement admitting any array with at least one item. |
| listRefinement | NonEmptyArray.listRefinement () | Returns a refinement admitting a non-empty array from a list, which is the shape structured wire formats use. |
| create | NonEmptyArray.create values | Admits a non-empty array, reporting the same failure the refinement does. |
| toArray | NonEmptyArray.toArray input | Returns a copy of the refined value as a standard array. |
| toList | NonEmptyArray.toList input | Returns the refined value as a standard list. |
| toNonEmptyList | NonEmptyArray.toNonEmptyList input | Converts to a non-empty list. |
| ofNonEmptyList | NonEmptyArray.ofNonEmptyList input | Converts from a non-empty list. |
| head | NonEmptyArray.head input | Returns the first item. |
| tail | NonEmptyArray.tail input | Returns every item after the first. |
| last | NonEmptyArray.last input | Returns the final item. |
| length | NonEmptyArray.length input | Returns the number of items as a plain int, matching Array.length. |
| map | NonEmptyArray.map mapping input | Applies a mapping to every item. |
| mapi | NonEmptyArray.mapi mapping input | Applies an index-aware mapping to every item. |
| append | NonEmptyArray.append first second | Concatenates two non-empty arrays. |
| rev | NonEmptyArray.rev input | Reverses the order of the items. |
| sort | NonEmptyArray.sort input | Sorts the items in ascending order. |
| sortBy | NonEmptyArray.sortBy projection input | Sorts the items by a projected key. |
| sortWith | NonEmptyArray.sortWith comparer input | Sorts the items using an explicit comparison. |
| reduce | NonEmptyArray.reduce reduction input | Combines every item with an associative operation. |
| fold | NonEmptyArray.fold folder state input | Folds over the items from an explicit seed. |
| min | NonEmptyArray.min input | Returns the smallest item. |
| max | NonEmptyArray.max input | Returns the largest item. |
| minBy | NonEmptyArray.minBy projection input | Returns the item with the smallest projected key. |
| maxBy | NonEmptyArray.maxBy projection input | Returns the item with the largest projected key. |
| filter | NonEmptyArray.filter predicate input | Filters the items, returning a standard array because emptiness is possible. |
| tryFilter | NonEmptyArray.tryFilter predicate input | Filters the items, returning None when nothing survives. |
| exists | NonEmptyArray.exists predicate input | Returns whether any item satisfies the predicate. |
| forall | NonEmptyArray.forall predicate input | Returns whether every item satisfies the predicate. |
| iter | NonEmptyArray.iter action input | Applies an action to every item. |
| consTo | NonEmptyArray.consTo head input | Prepends an item to an already non-empty array. |
| indexed | NonEmptyArray.indexed input | Pairs every item with its index. |
| collect | NonEmptyArray.collect mapping input | Maps each item to a non-empty array and concatenates the results. |
| concat | NonEmptyArray.concat input | Concatenates a non-empty array of non-empty arrays. |
| sortDescending | NonEmptyArray.sortDescending input | Sorts the items in descending order. |
| distinct | NonEmptyArray.distinct input | Removes duplicate items, preserving first-seen order. |
| zip | NonEmptyArray.zip first second | Pairs items positionally, truncating to the shorter input. |
| unzip | NonEmptyArray.unzip input | Splits a non-empty array of pairs into a pair of non-empty arrays. |
| reduceBack | NonEmptyArray.reduceBack reduction input | Combines every item from the right. |
| foldBack | NonEmptyArray.foldBack folder input state | Folds over the items from the right. |
| partition | NonEmptyArray.partition predicate input | Partitions the items into matching and non-matching standard arrays. |
| contains | NonEmptyArray.contains value input | Returns whether the array contains the item. |
| tryFind | NonEmptyArray.tryFind predicate input | Returns the first matching item, if any. |
| toSeq | NonEmptyArray.toSeq input | Returns the refined value as a sequence. |
| traverseResult | NonEmptyArray.traverseResult mapping input | Applies a fallible mapping to every item, accumulating every failure rather than stopping at the first. |
| sequenceResult | NonEmptyArray.sequenceResult input | Collects a non-empty array of results, accumulating every failure. |
| traverseOption | NonEmptyArray.traverseOption mapping input | Applies a mapping that may yield nothing, succeeding only when every item does. |
| sequenceOption | NonEmptyArray.sequenceOption input | Collects a non-empty array of options, succeeding only when every item is present. |
| groupBy | NonEmptyArray.groupBy projection input | Groups items by a key. |
| chunkBySize | NonEmptyArray.chunkBySize size input | Splits into consecutive runs of the given size, treating a size below one as one. |
| sum | NonEmptyArray.sum input | Adds every item, matching Array.sum. |
| sumBy | NonEmptyArray.sumBy projection input | Adds a projection of every item, matching Array.sumBy. |
| average | NonEmptyArray.average input | Averages the items. |
| averageBy | NonEmptyArray.averageBy projection input | Averages a projection of the items. |
| countBy | NonEmptyArray.countBy projection input | Counts the items sharing each key. |
| scan | NonEmptyArray.scan folder state input | Runs a fold and keeps every intermediate state, including the seed. |
| scanBack | NonEmptyArray.scanBack folder input state | Runs a fold from the right and keeps every intermediate state. |
| tryFindBack | NonEmptyArray.tryFindBack predicate input | Returns the last matching item, if any. |
| tryFindIndex | NonEmptyArray.tryFindIndex predicate input | Returns the index of the first matching item, if any. |
| tryPick | NonEmptyArray.tryPick chooser input | Returns the first item the chooser accepts, if any. |
| choose | NonEmptyArray.choose chooser input | Keeps the chosen items, returning a standard array because a chooser can reject every item. |
| tryChoose | NonEmptyArray.tryChoose chooser input | Keeps the chosen items, returning None when nothing survives. |
| tryItem | NonEmptyArray.tryItem index input | Returns the item at an index, or None when the index is out of range. |
| item | NonEmptyArray.item index input | Returns the item at an index, clamping the index into range. |
| truncate | NonEmptyArray.truncate count input | Keeps at most the first count items, treating a count below one as one. |
| skip | NonEmptyArray.skip count input | Drops the first count items, returning a standard array because skipping can consume everything. |
| pairwise | NonEmptyArray.pairwise input | Pairs each item with its successor, returning a standard array — a single item yields none. |
| iteri | NonEmptyArray.iteri action input | Applies an index-aware action to every item. |
| init | NonEmptyArray.init count initialiser | Builds an array of count items from their indices, treating a count below one as one. |
| replicate | NonEmptyArray.replicate count value | Builds an array of count copies, treating a count below one as one. |
| sortByDescending | NonEmptyArray.sortByDescending projection input | Sorts the items by a projected key, descending. |
| distinctBy | NonEmptyArray.distinctBy projection input | Removes items sharing a projected key, keeping the first of each. |
| allPairs | NonEmptyArray.allPairs first second | Every pairing of an item from each array. |
| map2 | NonEmptyArray.map2 mapping first second | Combines items positionally, truncating to the shorter input. |
Builds an array of exactly one item.
Parameters
| Name | Type | Description |
|---|---|---|
| value | 'a |
Returns
NonEmptyArray<'a>
Returns the non-empty array, or
None when the source is empty.Parameters
| Name | Type | Description |
|---|---|---|
| values | 'value array |
Returns
NonEmptyArray<'value> option
Returns the non-empty array, or
None when the source is empty.Parameters
| Name | Type | Description |
|---|---|---|
| values | 'a seq |
Returns
NonEmptyArray<'a> option
Returns the non-empty array, or
None when the source is empty.Parameters
| Name | Type | Description |
|---|---|---|
| values | 'a list |
Returns
NonEmptyArray<'a> option
Returns a refinement admitting any array with at least one item.
Parameters
| Name | Type | Description |
|---|---|---|
| unit |
Returns
Refinement<'value array, NonEmptyArray<'value>>
Returns a refinement admitting a non-empty array from a list, which is the shape
structured wire formats use.
Parameters
| Name | Type | Description |
|---|---|---|
| unit |
Returns
Refinement<'value list, NonEmptyArray<'value>>
Admits a non-empty array, reporting the same failure the refinement does.
Parameters
| Name | Type | Description |
|---|---|---|
| values | 'value seq |
Returns
Result<NonEmptyArray<'value>, Violation>
Returns a copy of the refined value as a standard array.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
'value[]
Returns the refined value as a standard list.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
'value list
Converts to a non-empty list.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
NonEmptyList<'value>
Converts from a non-empty list.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyList<'value> |
Returns
NonEmptyArray<'value>
Returns the first item. Total.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
'value
Returns every item after the first.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
'value[]
Returns the final item. Total.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
'value
Returns the number of items as a plain
int, matching Array.length.Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
int
Applies a mapping to every item. Non-emptiness is preserved.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | 'value -> 'a | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'a>
Applies an index-aware mapping to every item. Non-emptiness is preserved.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | int -> 'value -> 'a | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'a>
Concatenates two non-empty arrays.
Parameters
| Name | Type | Description |
|---|---|---|
| first | NonEmptyArray<'value> | |
| second | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Reverses the order of the items.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Sorts the items in ascending order.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Sorts the items by a projected key.
Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'value -> 'a | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Sorts the items using an explicit comparison.
Parameters
| Name | Type | Description |
|---|---|---|
| comparer | 'value -> 'value -> int | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Combines every item with an associative operation. Total — no seed required.
Parameters
| Name | Type | Description |
|---|---|---|
| reduction | 'value -> 'value -> 'value | |
| input | NonEmptyArray<'value> |
Returns
'value
Folds over the items from an explicit seed.
Parameters
| Name | Type | Description |
|---|---|---|
| folder | 'a -> 'value -> 'a | |
| state | 'a | |
| input | NonEmptyArray<'value> |
Returns
'a
Returns the smallest item. Total.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
'value
Returns the largest item. Total.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
'value
Returns the item with the smallest projected key. Total.
Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'value -> 'a | |
| input | NonEmptyArray<'value> |
Returns
'value
Returns the item with the largest projected key. Total.
Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'value -> 'a | |
| input | NonEmptyArray<'value> |
Returns
'value
Filters the items, returning a standard array because emptiness is possible.
Parameters
| Name | Type | Description |
|---|---|---|
| predicate | 'value -> bool | |
| input | NonEmptyArray<'value> |
Returns
'value[]
Filters the items, returning
None when nothing survives.Parameters
| Name | Type | Description |
|---|---|---|
| predicate | 'a -> bool | |
| input | NonEmptyArray<'a> |
Returns
NonEmptyArray<'a> option
Returns whether any item satisfies the predicate.
Parameters
| Name | Type | Description |
|---|---|---|
| predicate | 'value -> bool | |
| input | NonEmptyArray<'value> |
Returns
bool
Returns whether every item satisfies the predicate.
Parameters
| Name | Type | Description |
|---|---|---|
| predicate | 'value -> bool | |
| input | NonEmptyArray<'value> |
Returns
bool
Applies an action to every item.
Parameters
| Name | Type | Description |
|---|---|---|
| action | 'value -> unit | |
| input | NonEmptyArray<'value> |
Returns
unit
Prepends an item to an already non-empty array.
Parameters
| Name | Type | Description |
|---|---|---|
| head | 'value | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Pairs every item with its index. Non-emptiness is preserved.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<int * 'value>
Maps each item to a non-empty array and concatenates the results.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | 'value -> NonEmptyArray<'result> | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'result>
Concatenates a non-empty array of non-empty arrays.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<NonEmptyArray<'value>> |
Returns
NonEmptyArray<'value>
Sorts the items in descending order.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Removes duplicate items, preserving first-seen order. Non-emptiness is preserved.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Pairs items positionally, truncating to the shorter input. Total.
Parameters
| Name | Type | Description |
|---|---|---|
| first | NonEmptyArray<'first> | |
| second | NonEmptyArray<'second> |
Returns
NonEmptyArray<'first * 'second>
Splits a non-empty array of pairs into a pair of non-empty arrays.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'first * 'second> |
Returns
NonEmptyArray<'first> * NonEmptyArray<'second>
Combines every item from the right. Total — no seed required.
Parameters
| Name | Type | Description |
|---|---|---|
| reduction | 'value -> 'value -> 'value | |
| input | NonEmptyArray<'value> |
Returns
'value
Folds over the items from the right.
Parameters
| Name | Type | Description |
|---|---|---|
| folder | 'value -> 'a -> 'a | |
| input | NonEmptyArray<'value> | |
| state | 'a |
Returns
'a
Partitions the items into matching and non-matching standard arrays.
Parameters
| Name | Type | Description |
|---|---|---|
| predicate | 'value -> bool | |
| input | NonEmptyArray<'value> |
Returns
'value[] * 'value[]
Returns whether the array contains the item.
Parameters
| Name | Type | Description |
|---|---|---|
| value | 'value | |
| input | NonEmptyArray<'value> |
Returns
bool
Returns the first matching item, if any.
Parameters
| Name | Type | Description |
|---|---|---|
| predicate | 'value -> bool | |
| input | NonEmptyArray<'value> |
Returns
'value option
Returns the refined value as a sequence.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
'value seq
Applies a fallible mapping to every item, accumulating every failure rather than
stopping at the first.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | 'value -> Result<'result, 'failure list> | |
| input | NonEmptyArray<'value> |
Returns
Result<NonEmptyArray<'result>, 'failure list>
Collects a non-empty array of results, accumulating every failure.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<Result<'value, 'failure list>> |
Returns
Result<NonEmptyArray<'value>, 'failure list>
Applies a mapping that may yield nothing, succeeding only when every item does.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | 'value -> 'result option | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'result> option
Collects a non-empty array of options, succeeding only when every item is present.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value option> |
Returns
NonEmptyArray<'value> option
Groups items by a key. Every group is non-empty by construction.
Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'value -> 'a | |
| input | NonEmptyArray<'value> |
Returns
Map<'a, NonEmptyArray<'value>>
Splits into consecutive runs of the given size, treating a size below one as one.
Every chunk is non-empty.
Parameters
| Name | Type | Description |
|---|---|---|
| size | int | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<NonEmptyArray<'value>>
Adds every item, matching
Array.sum.Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<^value> |
Returns
^value
Adds a projection of every item, matching
Array.sumBy.Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'value -> ^a | |
| input | NonEmptyArray<'value> |
Returns
^a
Averages the items. Total — the divisor is the length, which is always at least
one, so unlike
Array.average this cannot raise.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<^value> |
Returns
^value
Averages a projection of the items. Total, for the same reason as
average.Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'value -> ^a | |
| input | NonEmptyArray<'value> |
Returns
^a
Counts the items sharing each key. Every count is at least one.
Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'value -> 'a | |
| input | NonEmptyArray<'value> |
Returns
Map<'a, int>
Runs a fold and keeps every intermediate state, including the seed.
Parameters
| Name | Type | Description |
|---|---|---|
| folder | 'a -> 'value -> 'a | |
| state | 'a | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'a>
Runs a fold from the right and keeps every intermediate state.
Parameters
| Name | Type | Description |
|---|---|---|
| folder | 'value -> 'a -> 'a | |
| input | NonEmptyArray<'value> | |
| state | 'a |
Returns
NonEmptyArray<'a>
Returns the last matching item, if any.
Parameters
| Name | Type | Description |
|---|---|---|
| predicate | 'value -> bool | |
| input | NonEmptyArray<'value> |
Returns
'value option
Returns the index of the first matching item, if any.
Parameters
| Name | Type | Description |
|---|---|---|
| predicate | 'value -> bool | |
| input | NonEmptyArray<'value> |
Returns
int option
Returns the first item the chooser accepts, if any.
Parameters
| Name | Type | Description |
|---|---|---|
| chooser | 'value -> 'a option | |
| input | NonEmptyArray<'value> |
Returns
'a option
Keeps the chosen items, returning a standard array because a chooser can reject
every item.
Parameters
| Name | Type | Description |
|---|---|---|
| chooser | 'value -> 'a option | |
| input | NonEmptyArray<'value> |
Returns
'a[]
Keeps the chosen items, returning
None when nothing survives.Parameters
| Name | Type | Description |
|---|---|---|
| chooser | 'a -> 'b option | |
| input | NonEmptyArray<'a> |
Returns
NonEmptyArray<'b> option
Returns the item at an index, or
None when the index is out of range.Parameters
| Name | Type | Description |
|---|---|---|
| index | int | |
| input | NonEmptyArray<'value> |
Returns
'value option
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
| Name | Type | Description |
|---|---|---|
| index | int | |
| input | NonEmptyArray<'value> |
Returns
'value
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
| Name | Type | Description |
|---|---|---|
| count | int | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
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
| Name | Type | Description |
|---|---|---|
| count | int | |
| input | NonEmptyArray<'value> |
Returns
'value[]
Pairs each item with its successor, returning a standard array — a single item yields none.
Parameters
| Name | Type | Description |
|---|---|---|
| input | NonEmptyArray<'value> |
Returns
('value * 'value)[]
Applies an index-aware action to every item.
Parameters
| Name | Type | Description |
|---|---|---|
| action | int -> 'value -> unit | |
| input | NonEmptyArray<'value> |
Returns
unit
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
| Name | Type | Description |
|---|---|---|
| count | int | |
| initialiser | int -> 'a |
Returns
NonEmptyArray<'a>
Builds an array of
count copies, treating a count below one as one.Parameters
| Name | Type | Description |
|---|---|---|
| count | int | |
| value | 'a |
Returns
NonEmptyArray<'a>
Sorts the items by a projected key, descending.
Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'value -> 'a | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Removes items sharing a projected key, keeping the first of each. Non-emptiness is preserved.
Parameters
| Name | Type | Description |
|---|---|---|
| projection | 'value -> 'a | |
| input | NonEmptyArray<'value> |
Returns
NonEmptyArray<'value>
Every pairing of an item from each array. Non-emptiness is preserved.
Parameters
| Name | Type | Description |
|---|---|---|
| first | NonEmptyArray<'first> | |
| second | NonEmptyArray<'second> |
Returns
NonEmptyArray<'first * 'second>
Combines items positionally, truncating to the shorter input. Total — unlike
Array.map2, which raises when the lengths differ.
Parameters
| Name | Type | Description |
|---|---|---|
| mapping | 'first -> 'second -> 'a | |
| first | NonEmptyArray<'first> | |
| second | NonEmptyArray<'second> |
Returns
NonEmptyArray<'a>