title: Get parent object from stream
body: <p>I have this class:</p>
  
  <pre><code>public class StructUserType extends UserType {
  
      MembersList membersList = new MembersList();
  
      public List&lt;Member&gt; getMembers() {
          return Collections.unmodifiableList(membersList.members);
      }
  
      static class MembersList {
          List&lt;Member&gt; members = new ArrayList&lt;&gt;();
      }
  
      public static class Member implements Identifiable {
          private Integer id;
  
          public Integer getId() {
              return id;
          }
      }    
  } 
  </code></pre>
  
  <p>And I have a <code>List</code> object:</p>
  
  <pre><code>List&lt;SmbpUserType&gt; userTypes = new ArrayList&lt;&gt;();
  </code></pre>
  
  <p>I want find <code>Member</code> which is equal to a certain id. I tried as follows:</p>
  
  <pre><code>Integer id = 1;
  userTypes.stream()
                  .filter(StructUserType.class::isInstance)
                  .map(StructUserType.class::cast)
                  .forEach(structUserType -&gt; {
                      structUserType.getMembers()
                              .stream()
                              .filter(m -&gt; m.getId() == id)
                              .findFirst().orElse(null);
                  });
  </code></pre>
  
  <p>I want, when the filter in the internal stream runs and finds the first member, to return the parent element that this member contains, those <code>UserType</code>.</p>
  
  <p>Analog in the classical style:</p>
  
  <pre><code>for (UserType userType : userTypes) {
              if (userType instanceof StructUserType) {
                  List&lt;StructUserType.Member&gt; members = ((StructUserType) userType).getMembers();
  
                  for (StructUserType.Member member : members) {
                      if (member.getId() == id) {
                          return userType;
                      }
                  }
              }
          }
          return null;
  </code></pre>