title: Using Generics in completionHandler
body: <p>I have a simple app, that communicates with server via TCP Socket using custom protocol. I want to achieve HTTP-like response-request behaviour, abstracting from socket layer. 
  So I have simple protocol:</p>
  
  <pre><code>protocol ResponseType {
     init(with frame: SocketMessage)
  }
  </code></pre>
  
  <p>And some of examples:</p>
  
  <pre><code>struct MessageAck: ResponseType {
    var messageId: String
    init(with frame: SocketMessage) {
      messageId = frame.messageId
    }
  }
  </code></pre>
  
  <p>I created simple protocol for sending requests:</p>
  
  <pre><code>protocol APIClient {
    func send&lt;T: ResponseType&gt;(request: SocketAPIRequest, completion:  ((Result&lt;T&gt;) -&gt; Void)?)
  }
  
  enum SocketAPIRequest {
     case textMessage(messageId: String, ...)
     ...
  }
  </code></pre>
  
  <p>And finally:</p>
  
  <pre><code>enum Result&lt;T&gt; {
    case success(T)
    case failure(Error)
  }
  
  class SocketAPIClient: APIClient {
    typealias MessageId = String
    private var callbacks = [Receipt: ((Result&lt;ResponseType&gt;) -&gt; Void)]()
  
    ...
  
    func send&lt;T&gt;(request: SocketAPIRequest, completion: ((Result&lt;T&gt;) -&gt; Void)?) where T : ResponseType {
      ....
      callbacks[stompFrame.receiptId] = completion
      ....
    }
  }
  </code></pre>
  
  <p>So, when I want to store callback for each request, to call it after answer will be received, I got such error:</p>
  
  <pre><code>Cannot assign value of type '((Result&lt;T&gt;) -&gt; Void)?' to type '((Result&lt;ResponseType&gt;) -&gt; Void)?'
  </code></pre>
  
  <p>I guess the problem with mixing Type's and objects, or maybe something else.</p>