Hello! I am going through chapter 10, and when doing parallel requests for Events, in the book, we are instructed to use .merge() and chaining a .reduce() like so:
static func events(forLast days: Int = 360) -> Observable<[EOEvent]> {
let openEvents = events(forLast: days, closed: false)
let closedEvents = events(forLast: days, closed: true)
return Observable
.of(openEvents, closedEvents)
.merge()
.reduce([]) { (running, new) -> [EOEvent] in
running + new
}
}
What I don’t follow is why do we need to attach the reducer operator if the return of merge() will also be of type Observer<[EOEvent]>.
When I remove the reduce, I can see that the closure in combineLatest (where we combine categories and downloaded events) back in CategoriesViewController gets called twice, once with 0 events and then with all the events, but apart from that I cannot understand the difference.
I think a bit more of explanation on this would help me understand reduce and merge better. Thanks in advance for the help.