Either from exception
rparree opened this issue · 7 comments
rparree commented
Hi,
Is there a way of creating an Either from an expression that might yield an exception? Or perhaps are there plans to add a Try
(with a toEither
)? If there's demand for that (either a method like below or a full Try
type), i could look into that and send a pull request.
function fromTry(fn){
try{
return Either.right(fn())
} catch(e) {
return Either.left(e)
}
}
cwmyers commented
Yeah that would be awesome. I'm surprised I hadn't done that already. Let's start with your suggestion and then see whether a first class Try
type makes sense.
rparree commented
Ok i will do so this coming weekend.
ulfryk commented
Just to make things consistent with other stuff here, let's make it Either.fromTry(…)
;)
ulfryk commented
snapshot released as monet@0.9.0-422
wookieb commented
How about this? Can we merge it and release 0.9.1?