S01E01-networking
S01E01-networking copied to clipboard
Using flatMap in Webservice
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?