CombineExt icon indicating copy to clipboard operation
CombineExt copied to clipboard

Interest in a compactScan operator ?

Open twittemb opened this issue 4 years ago • 5 comments

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<A>(initial: A, _ nextPartialResult: (A, Output) -> A?) -> AnyPublisher<A, Failure>

What do you think?

twittemb avatar Aug 30 '21 17:08 twittemb

Hey @freak4pc do you think it would be valuable ?

Thanks.

twittemb avatar Sep 01 '21 17:09 twittemb

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

freak4pc avatar Sep 01 '21 19:09 freak4pc

Hey @freak4pc

I've made the PR -> https://github.com/CombineCommunity/CombineExt/pull/100

Let me know what you think.

Thanks.

twittemb avatar Sep 04 '21 16:09 twittemb

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

freak4pc avatar Sep 21 '21 18:09 freak4pc

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.

oconnelltoby avatar Jan 26 '23 15:01 oconnelltoby