gigobyte / purify

Functional programming library for TypeScript - https://gigobyte.github.io/purify/
ISC License
1.5k stars 57 forks source link

EitherAsync handling uncaught exceptions #686

Closed Kamatayon closed 5 hours ago

Kamatayon commented 5 months ago

Good day. I wanted to ask a question regarding EitherAsync behaviour, currently if you throw error ( not with throwE, but just throw it ), the run() will assign the exception value to the Left . From my understanding you put only programmatic or recoverable errors in Left. Isn't it better to throw exception rather than put it into the value with different type leading to all sorts of unexpected behaviour and hard to catch bugs? You might add type check, but this completely negates all benefits of the type system, what is the point of having type there if actually it can be assigned with any value. In the wild JS world, contrary to a for example, Haskell, a library method can throw a dozen of exceptions ( even default ones are capable of that ) and handling every single one is tiresome.

gigobyte commented 5 hours ago

Any user of the library is free to pick the level of type-safety they want for their code, in a perfect world everyone would type Left as Error as any exception could've happened during the execution, but that's not always practical.

Eliminating all exceptions and turning everything into a Left is part of the design of EitherAsync, so your suggestion is something that was considered but ultimately won't be implemented.