eclipse-collections icon indicating copy to clipboard operation
eclipse-collections copied to clipboard

Introduce MutableMapIterable.putIfAbsent taking a Function0

Open victornoel opened this issue 3 years ago • 2 comments

Add, on top of of Map.putIfAbsent(K, V), a new method MutableMapIterable.putIfAbsent(K, Function0<V>).

The use case is to both:

  • not instantiate the value if not needed (as with MutableMapIterable.getIfAbsentPut(K, Function0<V>))
  • know if the value was actually added (as with Map.putIfAbsent(K, V) when it returns null)

Ideally, I would like is to have the 3 behaviours:

  • not instantiate the value if not needed (as with MutableMapIterable.getIfAbsentPut(K, Function0<V>))
  • have the newly added or the existing value returned (as with MutableMapIterable.getIfAbsentPut(K, Function0<V>))
  • know if the value was actually added (as with Map.putIfAbsent(K, V) when it returns null)

But I don't see how it's possible to do so with one unique method :)

victornoel avatar Sep 26 '22 10:09 victornoel

Hello @victornoel , May i be assigned this issue. Thanks!

IamLRBA avatar Nov 21 '24 13:11 IamLRBA

@IamLRBA go ahead and submit a PR, there's no need to be assigned the issue first.

motlin avatar Nov 21 '24 15:11 motlin