Is there a way to turn on the collect() after it sees a certain value and then turn it off after it sees another?
I tried using map and filter upstream and that's totally wrong.
Here's my playground
import UIKit
import Foundation
import Combine
var subj = PassthroughSubject<Int, Never>()
for iter in 0...10 {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(iter)) {
print("send \(iter)")
subj.send(iter)
}
}
let queue = DispatchQueue(label: "Q")
let cancellable = subj.collect(.byTime(queue, .seconds(2))).sink(receiveCompletion: {
print("finish")
print($0)
}, receiveValue: {
print($0)
})
/* my print
send 0
send 1
send 2
[0, 1]
send 3
send 4
[2, 3]
send 5
send 6
[4, 5] // is there a way to only have it dispatch all the values after this point? After it sees a value of 5?
send 7
send 8
[6, 7]
send 9
send 10
[8, 9, 10]
*/