Wrap a value in a Result
object depending on its class.
wrap_in_result.Rd
This function is an important helper function for the result
function
wrapper.
Details
When a wrapped fn
successfully computes and returns a value, it is wrapped
into a Result
object according to the following rules.
A value of any class (i.e. S7::class_any
) is wrapped in a Success
by default.
Errors and Warnings (i.e. S7::class_error | S7::class_warning
) are wrapped in a Failure
by default
A Result
is passed through as is - no point wrapping a Result
in a Result
.
These rules are implemented through this function's method dispatch, and so class authors can provide methods to dictate how their specific class should be wrapped. However it is expected that the simple rules already defined should be sufficient for the vast majority of cases.