A Result class for functions that may return errors

2016-10-18 Thread Josh Tumath
At the moment, when we call a synchronous function that runs some kind of operation, there are two obvious ways of returning whether there has been an error: returning a boolean or throwing an error. Returning a boolean to show whether the operation worked is simple, but doesn't give any indica

Re: Re: A Result class for functions that may return errors

2016-10-18 Thread Josh Tumath
> Not sure if I'm missing something, but wouldn't it be trivial to code that > constructor in JS? Yes it would be trivial, but my design I came up with was an example. The point I wanted to get across was to have some sort of standard practice for error handling using `return` rather than `thro

Re: Re: A Result class for functions that may return errors

2016-10-18 Thread Josh Tumath
The issue with that, though, is returning `undefined` is really no different to returning `null` in a sense. Null is considered bad because errors can crop up from not handling null as a return value from a function. Using `undefined` does not solve the problem. It also isn’t able to explain the