Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
fun <K, V> lazyMap(initializer: (K) -> V): Map<K, V> {
val map = mutableMapOf<K, V>()
return map.withDefault { key ->
val newValue = initializer(key)
map[key] = newValue
return@withDefault newValue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment