List: The List Monad

ListR Documentation

The List Monad

Description

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)

# The bind operator is a "flat map" that combines output lists.
list(1, 2) %>-% \(x) list(x * 2, x / 2)


monad documentation built on Oct. 28, 2024, 5:07 p.m.