title: In Java streams is peek really only for debugging?
body: <p>I'm reading up about Java streams and discovering new things as I go along. One of the new things I found was the <code>peek()</code> function. Almost everything I've read on peek says it should be used to debug your Streams.</p>
  
  <p>What if I had a Stream where each Account has a username, password field and a login() and loggedIn() method.</p>
  
  <p>I also have</p>
  
  <pre><code>Consumer&lt;Account&gt; login = account -&gt; account.login();
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Predicate&lt;Account&gt; loggedIn = account -&gt; account.loggedIn();
  </code></pre>
  
  <p>Why would this be so bad?</p>
  
  <pre><code>List&lt;Account&gt; accounts; //assume it's been setup
  List&lt;Account&gt; loggedInAccount = 
  accounts.stream()
      .peek(login)
      .filter(loggedIn)
      .collect(Collectors.toList());
  </code></pre>
  
  <p>Now as far as I can tell this does exactly what it's intended to do. It;</p>
  
  <ul>
  <li>Takes a list of accounts</li>
  <li>Tries to log in to each account</li>
  <li>Filters out any account which aren't logged in</li>
  <li>Collects the logged in accounts into a new list</li>
  </ul>
  
  <p>What is the downside of doing something like this? Any reason I shouldn't proceed? Lastly, if not this solution then what?</p>
  
  <p>The original version of this used the .filter() method as follows;</p>
  
  <pre><code>.filter(account -&gt; {
          account.login();
          return account.loggedIn();
      })
  </code></pre>