jklmli / monapt

Options, Tries, and Futures for JavaScript / TypeScript
MIT License
172 stars 13 forks source link

Responding to an error in a Try #15

Closed mrmurphy closed 7 years ago

mrmurphy commented 7 years ago

The signature for match in Try doesn't pass the error into the handler:

match<B>(matcher: { Success: (a: A) => B, Failure: () => B }): B;

I see that if I have a Failure, I can access .exception to get at the error object. But the match function doesn't narrow down the type of Try to Failure for the handler block. I tried just doing an if (foo.isFailure) { foo.exception}..., but there doesn't appear to be a type guard function defined for Failure either.

What's the idiomatic way to get at the error associated with a failed Try?

And big thanks for the library, I've found myself using it more and more often as time goes on.