Data.Maybe
v11.3.15 • Optional Values
The Maybe type represents optional values. A value of type Maybe A either contains a value of type A (represented as Just x), or it is empty (represented as Nothing).
Types
Maybe :: * -> *
The Maybe type represents optional values.
Implementationdata Maybe A = Nothing | Just A
Foreigns
No foreign functions defined in this module.
Functions
maybe :: B -> (A -> B) -> Maybe A -> B
A common pattern to handle Maybe values by providing a default and a function.
Implementationmaybe def f m = case m of
Nothing -> def
Just x -> f x
from_maybe :: A -> Maybe A -> A
Extracts the value from a Maybe, returning the default if it's Nothing.
Implementationfrom_maybe def m = case m of
Nothing -> def
Just x -> x
is_nothing :: Maybe A -> Bool
Returns True if the value is Nothing.
Implementationis_nothing m = case m of
Nothing -> True
Just x -> False
is_just :: Maybe A -> Bool
Returns True if the value contains a result.
Implementationis_just m = case m of
Nothing -> False
Just x -> True