<div dir="ltr">I don't have anything intelligent to add, but I assume either<br><br>* It's a good / okay idea, not high priority<br>* putIfAbsent and computeIfAbsent are seen to be enough for lazy operations<br>* Something much more subtle and/or annoying about how it will affect the universe of map implementations.<br><br>Either way, just so there is something concrete to talk about:<br><br><font face="monospace">import module java.base;<br><br>public final class Maps {<br>    private Maps() {<br>    }<br>    <br>    private static final Object DEFAULT = new Object();<br><br>    @SuppressWarnings({"unchecked","rawtypes"})<br>    public static <K, V> V getOrCompute(<br>            Map<K, ? extends V> m, <br>            Object key, <br>            Function<? super K, ? extends V> compute<br>    ) {<br>        Object value = ((Map) m).getOrDefault(key, DEFAULT);<br>        if (value == DEFAULT) {<br>            return compute.apply((K) key);<br>        }<br>        else {<br>            return (V) value;<br>        }<br>    }<br>}</font><div><font face="monospace"><br></font></div><div><font face="arial, sans-serif">(Note the three needed casts - this might be difficult for the same reason </font><font face="monospace">Map#get</font><font face="arial, sans-serif"> takes an </font><font face="monospace">Object</font><font face="arial, sans-serif"> and not a </font><font face="monospace">K</font><font face="arial, sans-serif">)</font></div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Thu, Oct 16, 2025 at 7:20 PM Chris Bouchard <<a href="mailto:chris@upliftinglemma.net">chris@upliftinglemma.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="auto"><div>Alberto,</div><div dir="auto"><br></div><div dir="auto">I believe your getOrPut methods already exist as putIfAbsent and computeIfAbsent, unless I'm missing a subtle difference.<br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Thu, Oct 16, 2025, 14:20 Alberto Otero Rodríguez <<a href="mailto:alber84ou@gmail.com" target="_blank">alber84ou@gmail.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Also, other two new methods might be interesting if you want to get a value from a map, but if the key doesn't exist you want to insert that value in the map and return it:</div><div><br></div><div><div style="margin-left:40px">default V getOrPut(Object key, V defaultValue)</div><br></div><div style="margin-left:40px">
default V getOrPut(Object key,  Function<? super K, ? extends V> defaultValueFunction)</div></div></blockquote></div></div><div dir="auto"><br></div><div dir="auto">Chris</div><div dir="auto"><div class="gmail_quote" dir="auto"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
</blockquote></div></div></div>
</blockquote></div>