I have a subject which sends/receives an array of Data like PassthroughSubject<[Int], Never>()
. When a value is received I want to split the array in single values to manipulate them and afterwards collect them again.
I know that the issue is that the flatMap
never sends the completion Event. But how can I solves this issue? Or is there a better way to manipulate every value in an array with combine?
Edit: I don‘t want to complete the subject to collect. I want to collect the output of the sequencer.
Example:
import Combine
var storage = Set<AnyCancellable>()
let subject = PassthroughSubject<[Int], Never>()
subject
.flatMap { $0.publisher }
.map { $0 * 10 }
.collect()
.sink {
print($0) // Never called
}
.store(in: &storage)
subject.send([1, 2, 3, 4, 5])