title: Understanding Optional<T>.map()
body: <p>Reviewing an example use of <code>Optional</code> where the optional is first loaded with a database call and then mapped to a Spring security <code>UserDetails</code> instance.  The code looks like this:</p>
  
  <pre><code>Optional&lt;User&gt; user = userRepository.findByName(username);
  user.orElseThrow(()-&gt; new UsernameNotFoundException("Ahhh Shuckkkks!!!");
  return user.map(CustomUserDetails::new).get();
  </code></pre>
  
  <p>In the last line would that call equal <code>return new CustomUserDetails(user.get())</code>.</p>
  
  <p>Also anyone know if there's an even shorter more fluid way to write the above example? </p>