Avoiding temporal coupling

Suppose that we have a code statement that is dependent on another code statement, as shown in the following code:

func sendRequest() {     let sessionConfig = URLSessionConfiguration.default     let session = URLSession(configuration: sessionConfig,                              delegate: nil,                              delegateQueue: nil)     var url: URL?     var request: URLRequest     /* First request block starts: */     url = URL(string: "https://httpbin.org/get")     request = URLRequest(url: url! as URL)     request.httpMethod = "GET"     let task = session.dataTask(with: request) {         (data: Data?, response: URLResponse?, error: Error?) -> Void in         if (error == nil) {             let statusCode = (response as! HTTPURLResponse).statusCode  print("URL Session Task Succeeded: HTTP \(statusCode)") ...

Get Swift Functional Programming - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.