bind {result} | R Documentation |
Binds a result with another result or function to return a result
Description
If the second object is a function, its return value will be wrapped in a
result
object of subclass success
or failure
depending
on whether the function produces an error or warning. Bind is aliased with
then_try
.
If the second object is a function, its return value will be wrapped in a
result
object of subclass success
or failure
depending
on whether the function produces an error or warning. then_try
is
aliased with bind
.
Usage
bind(last_result, next_obj, ...)
then_try(last_result, next_obj, ...)
Arguments
last_result |
|
next_obj |
|
... |
additional arguments to pass to |
Value
result
object of subclass success
or failure
result
object of subclass success
or failure
See Also
Examples
times3 <- function(x, succeeds = TRUE) {
if (succeeds) success(x * 3)
else failure("func1 failed")
}
success(5) |> bind(times3) |> value()
success(5) |> bind(times3, succeeds = FALSE) |> is_failure()
failure("failed from the start") |> bind(times3) |> is_failure()
failure("failed from the start") |> bind(times3) |> value()
times3 <- function(x, succeeds = TRUE) {
if (succeeds) success(x * 3)
else failure("func1 failed")
}
success(5) |> then_try(times3) |> value()
success(5) |> then_try(times3, succeeds = FALSE) |> is_failure()
failure("failed from the start") |> then_try(times3) |> is_failure()
failure("failed from the start") |> then_try(times3) |> value()
[Package result version 0.1.0 Index]