Created
May 28, 2019 23:50
-
-
Save jraska/24c1ff2b5da3d4ac43ad7507b9189b80 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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