andrewinci/Insulator

View on GitHub
lib/helper/src/main/kotlin/insulator/CachedFactory.kt

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
package insulator

abstract class CachedFactory<K, V>(private val op: (K) -> V) {
    private val cache = mutableMapOf<K, V>()
    fun build(key: K): V = cache.getOrPut(key) { op(key) }
}