CombineExt icon indicating copy to clipboard operation
CombineExt copied to clipboard

Adds ConcatMap operator

Open ohitsdaniel opened this issue 5 years ago • 9 comments

Resolves #41.

@freak4pc mentioned in #41, that we could try using .flatMap(maxPublishers: 1, transform:) to achieve the functionality of ConcatMap. I added some tests to verify if this is true, but unfortunately it's not that easy. ;)

Unexpected behaviour:

  • .flatMap(maxPublishers: 1, transform:) does not buffer mapped publishers, discarding all publishers if there is an active one, leading to missing values.

ohitsdaniel avatar Nov 22 '20 11:11 ohitsdaniel

Codecov Report

Merging #68 (4caf28f) into main (730d272) will increase coverage by 0.02%. The diff coverage is 97.63%.

:exclamation: Current head 4caf28f differs from pull request most recent head 80ba6dd. Consider uploading reports for the commit 80ba6dd to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##             main      #68      +/-   ##
==========================================
+ Coverage   97.12%   97.15%   +0.02%     
==========================================
  Files          62       64       +2     
  Lines        3336     3546     +210     
==========================================
+ Hits         3240     3445     +205     
- Misses         96      101       +5     
Impacted Files Coverage Δ
Sources/Operators/ConcatMap.swift 94.73% <94.73%> (ø)
Sources/Common/DemandBuffer.swift 100.00% <100.00%> (ø)
Tests/ConcatMapTests.swift 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 730d272...80ba6dd. Read the comment docs.

codecov[bot] avatar Nov 22 '20 13:11 codecov[bot]

A gave it a go and implemented Publishers.ConcatMap. As this is my first custom combine operator / Publisher, I'm happy about any kind of feedback. 😸

ohitsdaniel avatar Nov 22 '20 13:11 ohitsdaniel

Hey @ohitsdaniel - are you interested in finishing this PR? Thanks :)

freak4pc avatar Mar 06 '21 16:03 freak4pc

Yes, just didn't find the time yet as I have been focusing on other projects. I'll see if I can squeeze it in next week. :)

ohitsdaniel avatar Mar 06 '21 16:03 ohitsdaniel

Quick update from my side: I scheduled some time this Friday to work on this. :)

ohitsdaniel avatar Mar 23 '21 07:03 ohitsdaniel

@freak4pc

Re-implemented it, pretty closely following the RxSwift implementation while not over-generifying the implementation. Main idea is that we have an inner and outer sink.

The OuterSink observes the stream of upstream values and has .unlimited demand. Whenever it receives a value, it transforms it into a new publisher (NewPublisher) and hands it to the inner sink.

The InnerSink observes a stream of NewPublisher values and manages the demand. Whenever it receives a completion, it subscribes to the next publisher, if there is one. Whenever the outer sink hands in a NewPublisher, the inner sink either directly subscribes to the new publisher, if it currently has no active subscription, or queues it, so that it is subscribed to whenever the currently active subscription ends (i.e. the inner sink receives a successful completion).

Had to add a remainingDemand field to DemandBuffer, so that the inner sink can request more values from the next subscription if the downstream demand hasn't been fulfilled.

ohitsdaniel avatar Apr 12 '21 08:04 ohitsdaniel

@freak4pc Any plans to move on with this?

filblue avatar May 12 '21 14:05 filblue

Hey, are there any plans to merge this?

kerrmarin-lvmh avatar Jul 30 '22 16:07 kerrmarin-lvmh

bump

Evertt avatar Feb 09 '24 00:02 Evertt