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

feat: Adds cachedFlatMap operator #20

Merged
merged 15 commits into from
May 7, 2024
Merged

feat: Adds cachedFlatMap operator #20

merged 15 commits into from
May 7, 2024

Conversation

mdboon
Copy link
Contributor

@mdboon mdboon commented May 7, 2024

No description provided.

@mdboon mdboon requested review from giraugh and andogq May 7, 2024 06:02
Copy link

changeset-bot bot commented May 7, 2024

🦋 Changeset detected

Latest commit: 0136323

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
windpipe Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@giraugh
Copy link
Contributor

giraugh commented May 7, 2024

Would this work as a special case of like a .flatReduce() or something like that? Could then build a helper for working with a cache on top of that?

someStream
   .flatReduce($.cacheReducer(
     new Map(),
     atom => /* snip: determine key */,
     atom => /* snip: determine value */,
   ))

Would also leave the door open to other reductions like summing

someStream
  .flatReduce($.sumReducer(atom => produceAsyncNumber(atom)))

Or a manual setup

someStream
  .flatReduce((acc, atom) => doAsyncStuff(acc, atom)) // should return a stream that emits once w/ next acc val

src/stream/higher-order.ts Outdated Show resolved Hide resolved
@andogq
Copy link
Member

andogq commented May 7, 2024

Would this work as a special case of like a .flatReduce() or something like that? Could then build a helper for working with a cache on top of that?

someStream
   .flatReduce($.cacheReducer(
     new Map(),
     atom => /* snip: determine key */,
     atom => /* snip: determine value */,
   ))

I think it's worthwhile having a publicly exposed cachedFlatMap (as Mark's done here), but it would be good if it were implemented in terms of flatReduce under the hood. I don't think we should worry about it for now, given that flatReduce doesn't exist atm.

(also mark is getting antsy, please help)

@andogq andogq merged commit a49c4ad into main May 7, 2024
1 check passed
@andogq andogq deleted the feat/cachedFlatMap branch May 7, 2024 06:17
@giraugh
Copy link
Contributor

giraugh commented May 7, 2024

Sounds good to me 👍
Roger roger, sending more ants 🐜 🐜 🐜 🐜

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

Successfully merging this pull request may close these issues.

3 participants