title: Guava: Set<K> + Function<K,V> = Map<K,V>?
body: <p>Is there an idiomatic way to take a <code>Set&lt;K&gt;</code> and a <code>Function&lt;K,V&gt;</code>, and get a <code>Map&lt;K,V&gt;</code> live view? (i.e. the <code>Map</code> is backed by the <code>Set</code> and <code>Function</code> combo, and if e.g. an element is added to the <code>Set</code>, then the corresponding entry also exists in the <code>Map</code>).</p>
  
  <p>(see e.g. <a href="http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/collect/Collections2.html#filter%28java.util.Collection,%20com.google.common.base.Predicate%29" rel="noreferrer"><code>Collections2.filter</code></a> for more discussion on live views)</p>
  
  <hr>
  
  <p>What if a live view is not needed? Is there something better than this:</p>
  
  <pre><code>public static &lt;K,V&gt; Map&lt;K,V&gt; newMapFrom(Set&lt;K&gt; keys, Function&lt;? super K,V&gt; f) {
      Map&lt;K,V&gt; map = Maps.newHashMap();
      for (K k : keys) {
          map.put(k, f.apply(k));
      }
      return map;
  }
  </code></pre>