🗃️ SealedKommons#
A modern KSP-based alternative to sealed-enum for Kotlin Multiplatform. It's not as feature-rich as sealed-enum yet, but it contains the most important part: generating a list of entries.
🎯 Supported Targets#
The following targets are supported:
| Platform | Targets |
|---|---|
| JVM & Android | jvm, android |
| Apple | ios, macos, tvos, watchos |
| Web | js, wasmJs |
| Native & Other | androidNative, linux, mingw, wasmWasi |
🚀 Installation#
Integration using Version Catalog is highly recommended for aligned version usage.
First declare the library in your Version Catalog:
[libraries]
kommons-sealed = { group = "dev.datlag.kommons", name = "sealed", version.ref = "kommons" }
kommons-sealed-processor = { group = "dev.datlag.kommons", name = "sealed-processor", version.ref = "kommons" }
Then add the dependency to your module:
🛠️ Usage#
Simply annotate your sealed class or sealed interface with @SealedKommons and make sure to create a companion object for it.
@SealedKommons
sealed interface MySealedInterface {
object A : MySealedInterface
data object B : MySealedInterface
sealed interface C : MySealedInterface {
object D : C
}
companion object
}
You can now use the generated list of entries which contains all objects or data objects of this sealed interface or it's subtypes:
The entries variable looks like this under the hood: