The list built-in type is a monad with element-wise function application
as fmap() and flattening as join(). It follows that %>>% is a map
operator and %>-% is a "flat map" operator. The methods are implemented
as wrappers to the purrr package.
See also
purrr::map() which implements fmap() for list.
purrr::list_flatten() which implements join() for list.
Other monads:
Maybe
Examples
# The fmap operator corresponds to purrr::map().
list(1, 2) %>>% `+`(1)
#> [[1]]
#> [1] 2
#>
#> [[2]]
#> [1] 3
#>
# The bind operator is a "flat map" that combines output lists.
list(1, 2) %>-% \(x) list(x * 2, x / 2)
#> [[1]]
#> [1] 2
#>
#> [[2]]
#> [1] 0.5
#>
#> [[3]]
#> [1] 4
#>
#> [[4]]
#> [1] 1
#>