Safely executes a function, catching any errors.
The return type of the function.
The type of the error.
The function to execute.
A function to map errors to a specific type.
A Result containing either the function's return value or the caught error.
const [error, data] = resultFrom(() => JSON.parse('{"foo": "bar"}'));if (error) { console.error(error.message);} else { console.log(data);} Copy
const [error, data] = resultFrom(() => JSON.parse('{"foo": "bar"}'));if (error) { console.error(error.message);} else { console.log(data);}
Safely executes a function, catching any errors.