maybe_map: Apply a one-track function to a two-track argument.

Description Usage Arguments Format Value See Also Examples

Description

Similar to "bind" but maybe_map passes its argument to the continuation function and evaluates the resulting expression immediately rather than wrapping it in an anonymous function to be evaluated later. This is particular useful when using magrittr piping operators to compose chains of function calls.

Usage

1
maybe_map(m, f)

Arguments

m

A Maybe (two-track) value.

f

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

Format

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

Value

A Maybe (two-track) value

See Also

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

Examples

1
2
3
4
5
library("magrittr")
library(assertthat)
Just(1) %>% maybe_map(is.numeric) # Just(TRUE)
Just("cat") %>% maybe_map(is.numeric) # Just(FALSE)
Nothing() %>% maybe_map(is.numeric) # Nothing()

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