P-Y on Nostr: Everybody loves singletons, so we gotta have singleton support! Let's add a ...
Everybody loves singletons, so we gotta have singleton support!
Let's add a `installSingleton()` utility, that will leverage the `install()` utility we just defined:
```
inline fun <reified T> Linker.installSingleton(noinline factory: Linker.() -> T) {
var instance = UNINITIALIZED
install {
if (instance === UNINITIALIZED) {
instance = factory()
}
instance as T
}
}
var UNINITIALIZED: Any? = Any()
```
(This isn't thread safe. Who cares?)
Let's add a `installSingleton()` utility, that will leverage the `install()` utility we just defined:
```
inline fun <reified T> Linker.installSingleton(noinline factory: Linker.() -> T) {
var instance = UNINITIALIZED
install {
if (instance === UNINITIALIZED) {
instance = factory()
}
instance as T
}
}
var UNINITIALIZED: Any? = Any()
```
(This isn't thread safe. Who cares?)