typescript-optional icon indicating copy to clipboard operation
typescript-optional copied to clipboard

implement OptionalT

Open knightpop opened this issue 6 years ago • 1 comments

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

knightpop avatar May 26 '19 10:05 knightpop

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.

Nift avatar Jul 29 '19 15:07 Nift