I read Chapter 3 and found it strange that after the replaceNil
operator I had to do map with force unwrapping.
It turned out that this is because replaceNil
has two implementations for Publishers.Sequence
.
_ = Just<Int?>(1)
.replaceNil(with: 2) // Publishers.Map<Just<Int?>, T>
.sink(receiveValue: { (value: Int) in
print(value)
})
_ = [1, nil, 3]
.publisher
.replaceNil(with: 2) // Publishers.Sequence<[Publishers.Sequence<Elements, Failure>.Output], Failure>
.sink(receiveValue: { (value: Int?) in
print(value)
})
_ = [1, nil, 3]
.publisher
.replaceNil(with: 2) // Publishers.Map<Publishers.Sequence<[Int?], Never>, T>
.sink(receiveValue: { (value: Int) in
print(value)
})