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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.