title: Trying to understand lambda and stream in Java 8
body: <p>I am trying to understand Lambdas in Java 8.</p>
  
  <p>Say I have a Person class that looks like this:</p>
  
  <pre><code>public class Person implements {
      String name;
      GenderEnum gender;
      int age;
      List&lt;Person&gt; children;
  }
  </code></pre>
  
  <p>Now what I want to do is find all persons which are female, that have children that are younger than 10 years old.</p>
  
  <p>Pre java 8 I would do it like this:</p>
  
  <pre><code>List&lt;Person&gt; allPersons = somePeople();
  List&lt;Person&gt; allFemaleWithChildren = new ArrayList&lt;&gt;();
  for(Person p : allPersons) {
      for(Person child : p.getChildren()) {
          if(child.getAge() &lt; 10 &amp;&amp; p.getGender() == GenderEnum.Female) {
              allFemaleWithChildren.add(p);
          }
      }
  }
  </code></pre>
  
  <p>Now allFemaleWithChildren should have what I want.
  I have been trying to do the same using streams
  I think I need to use some sort of map, filter and reduce</p>
  
  <pre><code>allPersons.stream()
  //filter females
  .filter(p -&gt; p.getGender == GenderEnum.Female)
  //get the children
  .map(c -&gt; c.getChildren())
  //filter the ones that are less than 10 years
  .filter(c -&gt; c.getAge() &lt; 10)
  //return a list with the result
  .collect(Collectors.toList())
  </code></pre>
  
  <p>But this code does not compile.
  What am I missing.</p>
  
  <p>Also, I don't understand what the reduce method can be used for.</p>
  
  <p>The compiler says
  <code>cannot resolve method getAge()</code>. This is because <code>c</code> is apparently a collection and not the items in the collection, which is really what I want.</p>