Use the map
operator in Combine to transform values from one type to another.
import Combine
(1...3).publisher
.map { "\($0)" }
.sink { print($0) }
In the above code:
- The publisher emits values from
1
to3
. - The
map
operator transforms the emitted value to a string representation. - The
sink
subscriber prints the transformed values.
The output of the above code will be:
1
2
3