A list with at least one element
Create list from a range of values.
The first value is guaranteed to appear in the list.
Same as map but the function is also applied to the index of each element (starting at zero).
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
Extract the rest of the list.
head (range 1 5) == [ 2, 3, 4, 5 ]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 ) ])
== ( SizedList "a" [ "b", "c" ], SizedList 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) == FalseReverse a list.
reverse (range 1 3)
|> toList
== [ 5, 4, 3, 2, 1 ]Returns 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 2Remove 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 ]Update element at the given index
updateAt 2 negate (range 1 5)
|> toList
== [ 1, 2, -3, 4, 5 ]Unsafe version of fromList.
WARNING: Use it only when you know the list length for sure.
Using this function, we can wrap a regular list without scanning for its length, which is considerably faster. However, it can also create inconsistent objects with a reported size is different from the actual data length.
A list of a`s with at least 2 elements.
Meta information can be associated to each segment pair.