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

Interest in a compactScan operator ? #98

Open
twittemb opened this issue Aug 30, 2021 · 5 comments
Open

Interest in a compactScan operator ? #98

twittemb opened this issue Aug 30, 2021 · 5 comments
Labels
operator question Further information is requested

Comments

@twittemb
Copy link
Member

Hi everyone,

lately I faced a use case where a reducer function that I pass to a “scan” operator could return an optional.

the expected behaviour was: if the function returns nil then there is no change made in the accumulator and the scan operator continues with the next values.

the signature would be something like:

compactScan(initial: A, _ nextPartialResult: (A, Output) -> A?) -> AnyPublisher<A, Failure>

What do you think?

@twittemb twittemb added question Further information is requested operator labels Aug 30, 2021
@twittemb
Copy link
Member Author

twittemb commented Sep 1, 2021

Hey @freak4pc do you think it would be valuable ?

Thanks.

@freak4pc
Copy link
Member

freak4pc commented Sep 1, 2021

That sounds like a fun and useful operator, I would be up for accepting a PR for it :) Thanks!

@twittemb
Copy link
Member Author

twittemb commented Sep 4, 2021

Hey @freak4pc

I've made the PR -> #100

Let me know what you think.

Thanks.

@freak4pc
Copy link
Member

I kinda like the idea. Anyone has additional opinions about it? @CombineCommunity/contributors

@oconnelltoby
Copy link

I think a better signature could be:

scan(into: A, _ nextPartialResult: (inout A, Output) -> Void) -> AnyPublisher<A, Failure>

This would allow the user to achieve the same thing by simply not calling nextPartialResult when not needed rather than returning nil.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
operator question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants