Closed tosun-si closed 6 years ago
that's a good idea! I'll add it. Any idea for another name than getOrElse
? Maybe I can overload it, but overloading has been an annoyance for me with vavr sometimes, so I'm leaning towards giving it another name. I'm thinking maybe getOrCall
but unsure.
Yes, you can give this name.
What do you think about a "Try monad" in this API too ?
good question! Actually I've always been a little confused about Try
vs Either
in vavr. I don't really see the need for both, or maybe in the specific context of java, where there are checked exceptions. So my idea is to use Either
for both uses in prelude. For instance, there is FunctionX.liftEither:
It'll catch exceptions and return them as Either.Left
. I'm interested in any opinion on that topic!
I just released 0.6.1 on npm, which adds Option.getOrCall!
Thanks @emmanueltouzery !
For the Try monad, i can open a topic about this, if you want.
I think a monad is a good thing for errors handling.
The value is put in a composition and computational context.
Then, a default value can be obtained or a throw can be performed.
I think, this type of monad can serve for errors in general, not only for the checked exceptions present in Java.
After getting a value, it is easily possible to apply some higuer order functions like map or filter...
Do open a bug of course but I don't understand what Try gets you that Either doesn't. Right now it seems to me that Either gets us all we need, including everything you listed?
Cam you give an example, a use case? Something Try gives us that Either doesn't? I can't think of one.
also see http://emmanueltouzery.github.io/prelude.ts/latest/apidoc/classes/either.right.html#getorthrow
though I wouldn't advise throwing, but it's available.
Ok I'll watch your implementation of the either and keep you posted.
Sorry for disturbe you. I tented to install the version 0.6.1 with npm, but it indicates me that the version doen't exist.
You must have a typo somewhere, it's there, see:
Sorry, there was a proxy problem. Can i contact you in MP ? I want to use this API in a Angular 5 project, but i have some trouble.
I don't know what you call MP? If you have twitter you could direct message me, i'm @emmanueltouzery
otherwise general web setup instructions are there: https://github.com/emmanueltouzery/prelude.ts#using-in-the-browser
Ok, thanks for your help. Sorry for inconvenience.
Btw if you're still interested, regarding Try I now added Option.try_
, Option.tryNullable
and Either.try_
in prelude.
Hi Emmanuel,
Thanks for the info. And yes i am still interested :)
Hi @emmanueltouzery. I really like the idea of this API and like i am a FP fan.
I am using the VAVR in Java 8 projects.
I have a question, the API doesn't provide a "getOrElseGet" in the pattern Option, with a supplier in parameter (allows a lazy evaluation for the OR case).
Have you planned to add it in a futur release ?
Thanks for your help.