monet/monet.js

Either from exception

rparree opened this issue · 7 comments

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)
    }
}

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.

Ok i will do so this coming weekend.

Just to make things consistent with other stuff here, let's make it Either.fromTry(…) ;)

Also some work (alias attempt) is already started #189

(but seems to be abandoned)

snapshot released as monet@0.9.0-422

How about this? Can we merge it and release 0.9.1?

@wookieb it's merged wil be released with 0.9.1