Skip to contents

The package maybe implements the Maybe monad. Here method implementations for fmap(), bind() and join() are provided for the maybe S3 class from the package. The methods are simple wrappers for the corresponding functions in maybe.

See also

maybe::maybe_map() which implements fmap() for maybe values.

maybe::and_then() which implements bind() for maybe values.

Other monads: list

Examples

# The fmap operator corresponds to maybe::maybe_map().
maybe::just(1) %>>% `+`(1)
#> Just
#> [1] 2
maybe::nothing() %>>% `+`(1)
#> Nothing

# The bind operator corresponds to maybe::and_then().
maybe::just(1) %>-% \(x) maybe::just(x + 1)
#> Just
#> [1] 2
maybe::just(1) %>-% \(x) maybe::nothing()
#> Nothing
maybe::nothing() %>-% \(x) maybe::just(1)
#> Nothing