jklmli / monapt

Options, Tries, and Futures for JavaScript / TypeScript
MIT License
172 stars 13 forks source link

feat(future): add flatMapP function #18

Closed mrmurphy closed 7 years ago

mrmurphy commented 7 years ago

Add Future#flatMapP for continuing a Future chain by returning a Promise instead of another Future. This makes working with async functions inside of futures a little more clean.

I just ended up wanting this while working today and added it in. I'm not sure whether it fits with your vision of what you want the API to look like, but it does make Futures a bit easier to use with async functions, so user doesn't have to wrap any async functions in a flatMap with a call to Future.create.

jklmli commented 7 years ago

Interesting idea, definitely worth more thought. I'll be out of the country for a few weeks, so might not be too responsive.

I'd say try it out for a few weeks as a typescript module augmentation and see how you like it.

mrmurphy commented 7 years ago

Sounds great! Have fun on your trip :).

jklmli commented 7 years ago

Have you tried this out? How has it worked out for you?

mrmurphy commented 7 years ago

I think I actually think I ended up going with straight promises instead of futures, so I didn't get to test it out very much. I hope you had a nice trip!

jklmli commented 7 years ago

Got it, thanks for following up.

Futures are definitely my personally least used abstraction. Guess that means that they need more work. 😄

jklmli commented 7 years ago

Going to close this for now, please re-open if you work on this again.