title: Collectors.toMap only if optional value is present
body: <p>I have a list of languages like english, french, etc. I also have a list of words like apple, orange, etc. For each word, I want to create a map that looks like this: </p>
  
  <p>Map map = {english = apple, italian = mela}</p>
  
  <p>In order to get the translatedWord, I have a function that returns an optional. Signature of the method looks like this:</p>
  
  <blockquote>
    <p><code>Optional&lt;TranslatedWord&gt; getTranslatedWord(String word, Language language);</code></p>
  </blockquote>
  
  <p>This is the code I have written to collect the words into a map</p>
  
  <pre><code>List&lt;Language&gt; languages = {english, italian, french};
  for(String w : words) {
     Map&lt;Language, TranslatedWord&gt; map = languages.stream().collect(Collectors.ToMap(language -&gt; language,
        language -&gt; getTranslatedWord(w, language));
  
     doSomethingWithThisMap(map);
  }
  </code></pre>
  
  <p>The problem is getTranslatedWord() returns an Optional. I need to collect it into the Map only if the optional has a value in it. How can I do this? </p>