lazyStatic

lazyStatic brings C++-like static locals to Kotlin Multiplatform.
How to use it
First, add the official Maven Central repository to your settings.gradle.kts:
pluginManagement {
repositories {
mavenCentral()
}
}
dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
Then add a dependency on the library and the Introspekt Gradle plugin in
your root buildscript:
plugins {
id("dev.karmakrafts.introspekt.introspekt-gradle-plugin") version "<version>"
}
kotlin {
sourceSets {
commonMain {
dependencies {
implementation("dev.karmakrafts.lazystatic:lazystatic-core:<version>")
}
}
}
}
Usage example
import dev.karmakrafts.lazystatic.lazyStatic
import dev.karmakrafts.lazystatic.LazyStaticStorage
import dev.karmakrafts.introspekt.util.SourceLocation
fun myFunction() {
myValue = lazyStatic { heavyComputation() }
myTlValue = lazyStatic(storage = LazyStaticStorage.THREAD_LOCAL) {
heavyComputationWithSeed(Uuid.random())
}
}
) {
myValue = lazyStatic(location) { heavyComputation2() }
}