:: Maybe a -> [a] package:rio
The
maybeToList function returns an empty list when given
Nothing or a singleton list when given
Just.
Examples
Basic usage:
>>> maybeToList (Just 7)
[7]
>>> maybeToList Nothing
[]
One can use
maybeToList to avoid pattern matching when combined
with a function that (safely) works on lists:
>>> import Text.Read ( readMaybe )
>>> sum $ maybeToList (readMaybe "3")
3
>>> sum $ maybeToList (readMaybe "")
0
List of elements of a structure, from left to right.
O(n) Convert a vector to a list
O(n) Convert different vector types
O(1) First element of a vector in a monad. See
indexM
for an explanation of why this is useful.
O(1) Last element of a vector in a monad. See
indexM for
an explanation of why this is useful.
O(1) First element in a monad without checking for empty
vectors. See
indexM for an explanation of why this is useful.
O(1) Last element in a monad without checking for empty
vectors. See
indexM for an explanation of why this is useful.