title: Return first match in Java 8 stream (similar to _.find)
body: <p>I have a static method that identifies a matching type from a set using java 8 streams. </p>
  
  <p>Rather than using <code>.filter</code> and <code>.findAny</code>, I'd like to use a method similar to lodash's <a href="https://lodash.com/docs#find" rel="nofollow">_.find</a>, that "Iterates over elements of collection and returns the first element predicate returns truthy for."</p>
  
  <p>a "find" type method would presumably make the code more performant and concise </p>
  
  <pre><code>public static List&lt;Class&gt; types = Arrays.asList(
      Contact.class,
      Response.class,
      Request.class   
  );
  
  public static Optional&lt;Class&gt; resolveTypeFromFieldNames(Set&lt;String&gt; itemFields) {
      return types
          .stream()
          .filter(itemType -&gt; {
              Set&lt;String&gt; fields = Arrays.stream(itemType.getDeclaredFields())
                      .filter(f -&gt; !f.isSynthetic())
                      .map(Field::getName)
                      .collect(Collectors.toSet());
              return itemFields.equals(fields);
          })
          .findAny();
  }
  </code></pre>