Maybe
Use Maybe when a value may be absent and the absent case needs no error
information.
Type and constructors
Maybe
Maybe(a) contains either no value or one value of type a.
Nothing
The expected type determines the parameter of Nothing.
Just
Both constructors are available to patterns.
Transforming
maybeMap
Calls the function for Just; Nothing passes through unchanged.
maybeAndThen
Calls the function for Just without nesting its Maybe result. Nothing
skips the function.
maybeFilter
Keeps a present value when the predicate returns True; otherwise returns
Nothing. An absent value never calls the predicate.
These transformations are O(1) apart from callback work.
Defaults and alternatives
maybeWithDefault
Returns the first argument only for Nothing.
maybeOrElse
Returns the second argument when it is Just; otherwise returns the fallback
passed first.
Inspection
maybeIsJust
maybeIsNothing
Conversion
maybeToList
Maps Nothing to [] and Just value to [value].
maybeFromList
Uses the first list value, or returns Nothing for an empty list. The remainder
is ignored.
Use Result instead when the absent branch should carry an error.