Interest in a compactScan operator ?
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?
Hey @freak4pc do you think it would be valuable ?
Thanks.
That sounds like a fun and useful operator, I would be up for accepting a PR for it :) Thanks!
Hey @freak4pc
I've made the PR -> https://github.com/CombineCommunity/CombineExt/pull/100
Let me know what you think.
Thanks.
I kinda like the idea. Anyone has additional opinions about it? @CombineCommunity/contributors
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.