
The tie function stands for throw if error. It takes a value and throws an error if the value is an error.
import { tie } from '@aracna/core';
function divide(a, b) {
if (b === 0) {
return tie(new Error('cannot divide by zero'));
}
return a / b;
}
// will log 1.5
console.log(divide(3, 2));
// will log Error: cannot divide by zero
console.log(divide(1, 0));