safeCallback
Runs a callback in a safe block. If the callback throws, the function returns a "callback" typed Left instead of propagating the exception. If the callback returns an Either, it is kept as-is.
Interactive example
Syntax
typescript
function safeCallback<
GenericOutput extends unknown
>(
theFunction: () => GenericOutput
): ComputeSafeCallbackResult<GenericOutput> | CallbackError;Parameters
theFunction: Callback to execute in a safe block.
Return value
- If the callback returns an
LeftorRight: theEitheris returned as-is. - If the callback succeeds with a non-
Eithervalue: the value is wrapped inCallbackSuccess. - If the callback throws:
CallbackError(alias ofleft("callback", error)).
See also
left– Build a typedLeft.whenHasInformation– Pattern match on"callback".
