Inspired by Scala's Try
classes (including Success
and Failure
).
By using try-or-die
you can avoid most try-catch blocks in your code. That is because try-or-die
wraps around possible exceptions and simply returns the thing you want, or whatever else you want.
Don't get it? Here is an example that will always succeed:
let result = Try<User>(() => userFactory.create('Jack'))
.map(e => e.name)
.map(e => e.substr(-1) === 'k')
.value;
// Result will be true.
console.log(result);