Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Feature request: Multi-arg flatMap #615

Closed
jessekelly881 opened this issue Aug 21, 2023 · 3 comments
Closed

Feature request: Multi-arg flatMap #615

jessekelly881 opened this issue Aug 21, 2023 · 3 comments

Comments

@jessekelly881
Copy link
Contributor

jessekelly881 commented Aug 21, 2023

It's very common (at least in the code I write) to have multiple Effect.flatMap chains. It would be very useful to extend the flatMap function to help reduce boilerplate.

Effect.flatMap( // Effect<..., C>
    Effect<..., A>
    (a: A) => Effect<..., B>,
    (a: B) => Effect<..., C>,
    // etc...
)
@fubhy
Copy link
Member

fubhy commented Aug 21, 2023

Overloading an api with alternative syntax for the same things should generally be avoided unless there's a real benefit to it. In this case, I'm doubtful that adding built-in pipe-like behavior to flatMap (or any other operator) would be beneficial. In my opinion, this'd negatively impact readability and composability.

Effect.flatMap( // Effect<..., C>
    Effect<..., A>
    (a: A) => Effect<..., B>,
    (a: B) => Effect<..., C>,
    // etc...
)

vs.

pipe(
  // ...
  Effect.flatMap(...),
  Effect.flatMap(...),
  Effect.flatMap(...),
  // etc...
)

I personally prefer the latter.

@mikearnaldi
Copy link
Member

I feel like adding this only to flatMap would be awkward and adding it everywhere counter-productive, it is also a good use case for generators so the motivation isn't too strong for it to be included in the library

@jessekelly881
Copy link
Contributor Author

Makes sense. Ok. I'll close this for now.

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

No branches or pull requests

3 participants