listToMaybe -package:yaya

The listToMaybe function returns Nothing on an empty list or Just a where a is the first element of the list.

Examples

Basic usage:
>>> listToMaybe []
Nothing
>>> listToMaybe [9]
Just 9
>>> listToMaybe [1,2,3]
Just 1
Composing maybeToList with listToMaybe should be the identity on singleton/empty lists:
>>> maybeToList $ listToMaybe [5]
[5]

>>> maybeToList $ listToMaybe []
[]
But not on lists with more than one element:
>>> maybeToList $ listToMaybe [1,2,3]
[1]
Analogous to listToMaybe in Data.Maybe.
Convert between (the head of) a (singleton) list and Maybe (see listToMaybe). (invert maybeToList)
Converts a list to an Automaton in MaybeT, which outputs an element of the list at each step, throwing Nothing when the list ends.
Converts a list to an MSF in MaybeT, which outputs an element of the list at each step, throwing Nothing when the list ends.
Returns Nothing on an empty list or Just a where a is the first element of the slist.

Examples

Basic usage:
>>> slistToMaybe mempty
Nothing
>>> slistToMaybe (one 42)
Just 42
>>> slistToMaybe (cons 1 $ cons 2 $ one 3)
Just 1
Laws :
slistToMaybe . maybeToList ≡ id
Reverse is right only on singleton/empty lists
maybeToList . slistToMaybe {empty, singleton slist} ≡ {empty, singleton slist}