Skip to contents

This function is an important helper function for the result function wrapper.

Usage

wrap_in_result(x, ...)

Arguments

x

The object to be wrapped into a Result.

...

Additional optional arguments that may be used by individual methods.

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.

See also