Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement OptionalT #24

Open
knightpop opened this issue May 26, 2019 · 1 comment
Open

implement OptionalT #24

knightpop opened this issue May 26, 2019 · 1 comment

Comments

@knightpop
Copy link

Hello, Thanks for making this wonderful library.

When I use this with Promise, I need to map and flatMap inside Optional value.

UseCase is like this.

const pNum = Promise.resolve(Optional.of(1));
const num = await pNum;
const plusOneNum: Optional<number> = num.map(n => n + 1);

If I have OptionalT

const pOTNum = OptionalT.from(Promise.resolve(Optional.of(1)));
const plusOneNum: OptionalT<Promise, number> = pOTNum.map(n => n + 1);
const result = (await plusOneNum.value).get();

You can see detail of OptionT(It's implement in scala, but I think you can understand it!)

@Nift
Copy link

Nift commented Jul 29, 2019

Please delete this comment if it is inappropriate, but I just happened top stop by this repo and issue when googling around.

As your issue has not been responded to in 2 months @knightpop I figured you might take a look at a repo I made which does exactly the same, but is not inspired by Java/Scala naming: https://github.com/Nift/Optional

It has implemented both mapAsync and flatMapAsync which should help your issue. Additionally, it has base .map and .flatMap as well which can be used without a Promise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants