gkaimakas
gkaimakas

Reputation: 582

Transform SignalProducer that emits arrays to SignalProducer that emits all elements of the original array

Let's say that I have a SignalProducer<[Element], Error> that emits an array of elements when started.

I would like to transform that SignalProducer to a new SignalProducer<Element, Error> that emits each element of the [Element] array consecutively.

What is the best approach to do so?

Upvotes: 1

Views: 144

Answers (1)

Rui Peres
Rui Peres

Reputation: 25917

You can do something like this:

let firstProducer: SignalProducer<[Element], Error> = // something
let toSingleElement: [Element] -> SignalProducer<Element, Error> = { SignalProducer(values: $0) }

let secondProducer = firstProducer.flatMap(.Concat, transform: toSingleElement)

You can also use Rex's operator: uncollect.

Upvotes: 3

Related Questions