2 ms·
That's a limit of exception handling in Elixir. A good language treats errors as a first class type. Functions that can error have no business returning an A.
by epolanski 4y ago
That's a limit of exception handling in Elixir.
A good language treats errors as a first class type. Functions that can error have no business returning an A.
Example given, the fetch API, is basically typed as fetch<A>(): Promise<A>
In reality, there might not be A at all, it should return a data type such as Either (or Result) which encodes linearly and forces the consumer to consider and handle the error.
- dmix 4y agoThere's nothing stopping JS devs from combining pipes with heavy use of a Maybe library. You don't need to use pipes everywhere, but it would be useful for a system that was designed with that pattern in mind. I already use Maybe patterns quiet a bit in my TS project but there always the libraries and frameworks you work with that don't. So yeah I can see it being a language level thing (the way Promises were used) pushing for wide adoption.
- crabmusket 4y agoIn this case, Promise already includes the possibility of rejection, though the types that may be rejected are not specified.
- josevalim 4y agoElixir handles errors as you describe, the example does not cover it. The pipeline also assumes a single direction, which pushes error handling to the next step, but there are also constructs (case and with) for handling and composing errors in one go.