• OK, I just fell in 😍 with stdlib’s Result(catching:).

    extension Request where Response: Decodable {
        func handle(response: Result<Data, Error>, 
                              completion: (Result<Response, Error>) -> Void) {
            completion(Result { 
                try JSONDecoder().decode(Response.self, from: response.get())
            })
        }
    }
    
  • Reminder: If you’re running into limitations with default parameters (for example, the value can’t be computed, they can’t specialize a generic, defaults don’t exist in literals), you can always replace a default with an explicit overload.

    func f(x: Int = 0) {}
    

    is the same as

    func f(x: Int) {}
    func f() { f(0) }
    

    stackoverflow.com/questions…

subscribe via RSS