NonEmptyArrayModule
Operations over arrays that carry their non-emptiness in the type.
Summary
| Name | Signature | Synopsis |
|---|---|---|
| Union cases | ||
| ToArray | this.ToArray | Returns a copy of the refined value as a standard array. |
| Length | this.Length | Returns the number of items, which is always at least one. |
| Tail | this.Tail | Returns all items after the head. |
| Head | this.Head | Returns the first item. |
| Operations | ||
| 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. |
Union cases
kind:member
kind:member
Operations
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
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>
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind: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
| Name | Type | Description |
|---|---|---|
| count | int | |
| input | NonEmptyArray<'value> |
Returns
'value[]
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
kind:member
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>