safeCallback
Runs a callback in a safe block. If the callback throws, the function returns a "callback" typed EitherLeft instead of propagating the exception.
Interactive example
Syntax
typescript
function safeCallback<GenericOutput extends unknown>(
theFunction: () => GenericOutput
): GenericOutput | EitherCallbackError;Parameters
theFunction: Callback to execute in a safe block.
Return value
- If the callback succeeds: the value returned by
theFunction. - If the callback throws:
EitherCallbackError(alias ofleft("callback", error)).
See also
left– Build a typedLeft.whenHasInformation– Pattern match on"callback".
