Wraps a function that may throw into a function that returns a Result.
The function to wrap that may throw an error
A label to identify the error when the function throws
A function that returns a Result
const safeJSONParse = fromThrowable(JSON.parse, 'PARSE_ERROR');const success = safeJSONParse('{"foo": "bar"}'); // [null, { foo: "bar" }]const fail = safeJSONParse('invalid json'); // [Err<'PARSE_ERROR'>, undefined] Copy
const safeJSONParse = fromThrowable(JSON.parse, 'PARSE_ERROR');const success = safeJSONParse('{"foo": "bar"}'); // [null, { foo: "bar" }]const fail = safeJSONParse('invalid json'); // [Err<'PARSE_ERROR'>, undefined]
Wraps a function that may throw into a function that returns a Result.