S01E01-networking icon indicating copy to clipboard operation
S01E01-networking copied to clipboard

Using flatMap in Webservice

Open yoching opened this issue 9 years ago • 0 comments

I watched this video. Great talk! Thank you!

In the video ( at about 8:07) , flatMap is used in load method of Webservice like this. (Actually, I copied this code from the article.)

final class Webservice {
    func load<A>(resource: Resource<A>, completion: (A?) -> ()) {
        NSURLSession.sharedSession().dataTaskWithURL(resource.url) { data, _, _ in
            let result = data.flatMap(resource.parse)
            completion(result)
        }.resume()
    }
}

However, in this sample code, flatMap is not used and guard let is used instead. Are there any reasons that this sample code does not use flatMap?

yoching avatar Jul 24 '16 15:07 yoching