title: Is there a convenience method to create a Predicate that tests if a field equals a given value?
body: <p>I often find myself in the need to filter a <code>Stream</code> or to use a predicate that checks if a given field has a given value.</p>
  
  <p>Say for example I have this POJO:</p>
  
  <pre><code>public class A {
      private Integer field;
  
      public A(final Integer field) {
          this.field = field;
      }
  
      public Integer getField() {
          return field;
      }
  }
  </code></pre>
  
  <p>And I want to filter a <code>Stream</code> of objects based on the value of the <code>field</code>:</p>
  
  <pre><code>    final Integer someValue = 42;
      Stream.of(new A(42), new A(1729), new A(42), new A(87539319), new A(null))
              .filter(a -&gt; Objects.equals(a.getField(), someValue))
              ...
  </code></pre>
  
  <p>Would there be a convenience method to generate the predicate for the <code>filter</code> method? I noticed there is <code>Predicate.isEqual</code> but it does not fit the need.</p>
  
  <p>I could quite easily write one like this:</p>
  
  <pre><code>public static &lt;T,R&gt; Predicate&lt;T&gt; isEqual(Function&lt;? super T, ? extends R&gt; f, R value) {
      return v -&gt; Objects.equals(value, f.apply(v));
  }
  </code></pre>
  
  <p>and use it as:</p>
  
  <pre><code>    Stream.of(new A(42), new A(1729), new A(42), new A(87539319), new A(null))
              .filter(isEqual(A::getField, someValue))
              ...
  </code></pre>
  
  <p>but I'd prefer to reuse an existing method from the JDK if possible.</p>