maybe {maybe} | R Documentation |
Modify a function to return a maybe value
Description
Wrapping a function in maybe
will modify it to return a maybe value. If
the function would normally return an error or warning the modified function
will return a 'Nothing' value, otherwise it will return a 'Just' value.
If a predicate function is provided with the parameter ensure
, if the
predicate returns TRUE
when evaluated on the return value of the function,
then a 'Just' value will be returned by the modified function, otherwise
it will return a 'Nothing' value.
Usage
maybe(.f, ensure = function(a) TRUE, allow_warning = FALSE)
Arguments
.f |
A function to modify |
ensure |
A predicate function |
allow_warning |
Whether warnings should result in 'Nothing' values |
Value
A function which returns maybe values
Examples
maybe(mean)(1:10)
maybe(mean, allow_warning = TRUE)("hello")
maybe(sqrt)("hello")
maybe(sqrt, ensure = not_infinite)(-1)
[Package maybe version 1.1.0 Index]