maybe_bind: Convert a one-track function to a two-track function.

Description Usage Arguments Format Value See Also Examples

Description

A “bind” function or method can be thought of as feeding an input value to a function. This is known as “binding” a value to the parameter of the function. When you need to use a function that does not already take a Maybe type argument, use maybe_bind to "lift" a new function that *does* take a Maybe type argument.

Usage

1

Arguments

f

A function taking a non-optional (one-track) argument and returning an optional (two-track) value.

Format

maybe_bind :: (a -> b) -> (Maybe a -> Maybe b)

Value

A function taking an optional (two-track) argument and returning an optional (two-track) value.

See Also

Other Maybe functions: as_maybe, is_nothing, maybe_apply, maybe_default, maybe_map_2, maybe_map_3, maybe_map_4, maybe_map_5, maybe_map, maybe_then, maybes_collapse, maybes_partition

Examples

1
2
3
4
5
library(assertthat)
is_maybe_numeric <- maybe_bind(is.numeric)
is_maybe_numeric(Just(1)) # Just(TRUE)
is_maybe_numeric(Just("cat")) # Just(FALSE)
is_maybe_numeric(Nothing()) # Nothing()

Teresa00/hfmAnnotation documentation built on May 14, 2019, 12:51 a.m.