title: How do I write the not/negate higher order function in swift?
body: <p>I am a Javascripter and I love using the <code>not/negate</code> function:</p>
  
  <pre><code>function not (predicateFunc) {
      return function () {
          return !predicateFunc.apply(this, arguments);
      };
  }
  </code></pre>
  
  <p>I am trying to do the same thing with swift:</p>
  
  <pre><code>func not &lt;A&gt; (_ f: @escaping (_ A: Any) -&gt; Bool) -&gt; (A) -&gt; Bool {
      return { a in !f(a) }
  }
  </code></pre>
  
  <p>But I am getting errors like</p>
  
  <pre><code>generic parameter 'T' could not be inferred
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Cannot convert value of type '(_) -&gt; Bool' to expected argument type '(Any) -&gt; Bool'
  </code></pre>
  
  <p>The outcome I am looking for is when I have a function like this:</p>
  
  <pre><code>func isEmpty&lt;T: Collection&gt;(collection: T) -&gt; Bool {
      return collection.count == 0
  }
  </code></pre>
  
  <p>I can just create a <code>notEmpty</code> function like this:</p>
  
  <pre><code>let notEmpty = not(isEmpty)
  </code></pre>
  
  <p>And then use it like </p>
  
  <pre><code>   notEmpty([3,4,5]) // true
  </code></pre>
  
  <p>What am I doing wrong?</p>