When I first read the task for mergedStories
I initially thought about using a flatMap and wondered about the complexity used in that function (creating array, remainder, merge).
So I tried a different version that looks like this (trying to understand flatMap again):
func mergedStories2(ids: storyIDs: [Int]) -> AnyPublisher<Story, Error> {
storyIDs.publisher
.flatMap(story)
.eraseToAnyPublisher()
}
Using this much simpler looking function I get nearly the same result, although sometimes the order of stories printed differs (1000, 1002, 1001).
since I can’t really say I understood everything in detail I ask: what’s the problem with my function, why does the order differ sometimes (depending on web request latency) and whether this could also happen in the original approach, and how to avoid that.
Still trying to understand all the impacts.
Thanks for any insights.