Description
The Maybe type, and associated operations.
DocumentationThe Maybe
type encapsulates an optional value. A value of type
either contains a value of type Maybe
aa
(represented as
), or it is empty (represented as Just
aNothing
). Using Maybe
is a good way to deal with errors or exceptional cases without resorting to drastic measures such as error
.
The Maybe
type is also a monad. It is a simple kind of error monad, where all errors are represented by Nothing
. A richer error monad can be built using the Either
type.
maybe :: b -> (a -> b) -> Maybe a -> bSource
The maybe
function takes a default value, a function, and a Maybe
value. If the Maybe
value is Nothing
, the function returns the default value. Otherwise, it applies the function to the value inside the Just
and returns the result.
mapMaybe :: (a -> Maybe b) -> [a] -> [b]Source
The mapMaybe
function is a version of map
which can throw out elements. In particular, the functional argument returns something of type
. If this is Maybe
bNothing
, no element is added on to the result list. If it just
, then Just
bb
is included in the result list.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4