I'm looking for a method that allows you to react upon the previous output to create a new stream.
It would be similar to scan, but rather than returning an output, it would return another publisher that publishes the next result.
Here's something similar to the scan example:
func next(x: Int) -> AnyPublisher<Int?, Never> {
return Future { x < 5 ? $0(.success(x + 1)) : $0(.success(nil)) }
}
next(0)
.fold { x != nil ? next(x) : nil }
.collect()
// Yields [1, 2, 3, 4]
Something more real:
paginated(0)
.fold(limit: 100) { $0.index < $0.total ? paginated($0.index + 1) : nil }
.collect()
// Yields all pages as an array