I want a Publisher similar to Just
except it should emit multiple values, and then complete the stream.
Let's call it JustSeveral
:
func fibonacci(_ number: Int) -> AnyPublisher<Int, Never> {
Future { ... }.eraseToAnyPublisher()
}
JustSeveral([293, 18, 104])
.flatMap { fibonacci($0) }
.sink { print($0) }
Is there a way to combine operators with Just
to get the same thing, or do I need to build this Publisher myself?
Note: Any solution should be able to handle an arbitrary number of elements in the array, not just 3.
For example, if we had an uncollect
operator, this would be trivial:
Just([293, 18, 104])
.uncollect { $0 }
.flatMap { fibonacci($0) }
.sink { print($0) }