result {result} | R Documentation |
Wraps a function in an result
monad for later evaluation.
Description
Use result
on functions whose outcomes are not known in advance or not
safe to be examined. The function will not be evaluated until the monad is
explicitly called.
Usage
result(.fn, detect_warning = TRUE, fail_on_warning = TRUE)
Arguments
.fn |
function to wrap |
detect_warning |
logical, whether to detect warnings; note |
fail_on_warning |
logical, whether to treat warnings as |
Value
function that returns a result
object of subclass
success
or failure
Examples
crashy <- function() stop("Go no further")
safely_call_crashy <- result(crashy)
safely_call_crashy() |> is_failure()
calculate <- function(x, y) x + y
safely_calculate <- result(calculate)
safely_calculate(1, 2) |> value()
[Package result version 0.1.0 Index]