Skip to content

05nelsonm/immutable

Repository files navigation

immutable

badge-license badge-latest-release

badge-kotlin

badge-platform-android badge-platform-jvm badge-platform-js badge-platform-js-node badge-platform-wasm badge-platform-linux badge-platform-macos badge-platform-ios badge-platform-tvos badge-platform-watchos badge-platform-windows badge-support-android-native badge-support-apple-silicon badge-support-js-ir badge-support-linux-arm

Immutability utilities for Kotlin Multiplatform

Immutable Collections

Wrapper classes that implement Set, List, and Map interfaces which inhibit modification via casting.

Does not add any new class references, as all Immutable implementations are private classes.

Top level accessor functions either return the EmptySet, EmptyList, EmptyMap objects, or will copy & wrap the elements with the Immutable class implementation (if not already wrapped).

All collections/iterators returned by Immutable implementation functions are also Immutable.

fun main() {
    immutableSetOf("This", "That")
    immutableListOf("This", "That")
    immutableMapOf("This" to "That")
    
    // toImmutable
    setOf("This", "That").toImmutableSet()
    listOf("This", "That").toImmutableList()
    mapOf("This" to "That").toImmutableMap()
}

Get Started

dependencies {
    implementation("io.matthewnelson.immutable:collections:0.1.3")
}