A list with at least one element
Create list from a range of values.
The first value is guaranteed to appear in the list.
Generate a new List from iterating over pairs of elements in the NonEmpty list.
generate Tuple.pair (range 1 5)
== [ ( 1, 2 ), ( 2, 3 ), ( 3, 4 ), ( 4, 5 ) ]Try to create sequence from a list with at least two elements
Create NonEmpty from list, returning a singleton with the given default if list is empty.
Create NonEmpty from list, returning example if list is empty.
Same as map but the function is also applied to the index of each element (starting at zero).
Reduce a list from left using operator.
This version of foldl does not require an accumulator since the list is guaranteed to not being empty
Keep elements that satisfy the test.
Return a list, since result might be empty.
Filter out certain values.
Return a list, since result might be empty.
Put two lists together.
append (range 1 3) (range 4 5) == range 1 5Map a given function onto a list and flatten the resulting lists.
concatMap f xs == concat (map f xs)Places the given value between all members of the given list.
Apply a two argument function pairwise to elements of both lists
Apply a 3 argument function tuples of elements from all lists
Apply a 4 argument function tuples of elements from all lists
Apply a 5 argument function tuples of elements from all lists
Sort values with a custom comparison function.
This is also the most general sort function, allowing you to define any other: sort == sortWith compare
Take (at most) the first n elements.
The number of elements n must be n >= 1, otherwise it returns the singleton list.
take 2 (range 1 5)
|> toList
== [ 1, 2 ]WARNING: differently from lists, append (take n lst) (drop n lst) do not always recover
the original list.
Drop (at most) the first n elements.
The resulting list will have at least one element
drop 2 (range 1 5)
|> toList
== [ 3, 4, 5 ]Partition a list based on some test.
The first list contains all values that satisfy the test, and the second list contains all the value that do not.
Deconstruct list into the head and tail parts
uncons (range 1 5)
== ( 1, [ 2, 3, 4, 5 ] )Decompose a list of tuples into a tuple of lists.
unzip (create ( "a", 1 ) [ ( "b", 2 ), ( "c", 3 ) ])
== ( NonEmpty "a" [ "b", "c" ], NonEmpty 1 [ 2, 3 ] )Determine if all elements satisfy some test.
all (\x -> modBy 2 == 0) (range 1 5) == FalseDetermine if any elements satisfy some test.
any (\x -> modBy 2 == 0) (range 1 5) == TrueFind the minimum element in a non-empty list.
minimum (range 1 5) == 5Find the maximum element in a non-empty list.
maximum (range 1 5) == 5Get the sum of the list elements.
sum (range 1 5) == 1 + 2 + 3 + 4 + 5Figure out whether a list contains a value.
member 42 (range 1 3) == FalseReturns Just the element at the given index in the list, or Nothing if the index is out of range.
getAt 1 (range 1 5) == Just 2Insert element at given position.
insertAt 2 42 negate (range 1 5)
|> toList
== [ 1, 2, 42, 3, 4, 5 ]Remove the element at an index from a list.
Return the original list if the index is out of range or if the resulting list would be empty.
removeAt 2 negate (range 1 5)
|> toList
== [ 1, 2, 4, 5 ]
A list of a`s with at least 1 element.