getOrPut method
V
getOrPut(
- K key,
- V compute()
Gets a value or computes it if not present.
This is useful for caching expensive computations.
Implementation
V getOrPut(K key, V Function() compute) {
final existing = get(key);
if (existing != null) {
return existing;
}
final value = compute();
put(key, value);
return value;
}