{"id":13726033,"url":"https://github.com/Kotlin/kotlinx.collections.immutable","last_synced_at":"2025-05-07T21:30:56.549Z","repository":{"id":9837668,"uuid":"59769494","full_name":"Kotlin/kotlinx.collections.immutable","owner":"Kotlin","description":"Immutable persistent collections for Kotlin","archived":false,"fork":false,"pushed_at":"2025-05-06T13:03:24.000Z","size":1473,"stargazers_count":1272,"open_issues_count":58,"forks_count":63,"subscribers_count":50,"default_branch":"master","last_synced_at":"2025-05-06T13:25:17.692Z","etag":null,"topics":["collections","immutable","immutable-collections","kotlin"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Kotlin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-05-26T17:23:13.000Z","updated_at":"2025-05-06T12:10:24.000Z","dependencies_parsed_at":"2022-07-05T06:30:59.748Z","dependency_job_id":"4909b03b-d7cd-439b-9b28-05909f575768","html_url":"https://github.com/Kotlin/kotlinx.collections.immutable","commit_stats":{"total_commits":274,"total_committers":15,"mean_commits":"18.266666666666666","dds":0.551094890510949,"last_synced_commit":"d7b83a13fed459c032dab1b4665eda20a04c740f"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kotlin%2Fkotlinx.collections.immutable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kotlin%2Fkotlinx.collections.immutable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kotlin%2Fkotlinx.collections.immutable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Kotlin%2Fkotlinx.collections.immutable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Kotlin","download_url":"https://codeload.github.com/Kotlin/kotlinx.collections.immutable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252957111,"owners_count":21831437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["collections","immutable","immutable-collections","kotlin"],"created_at":"2024-08-03T01:02:49.540Z","updated_at":"2025-05-07T21:30:56.207Z","avatar_url":"https://github.com/Kotlin.png","language":"Kotlin","funding_links":[],"categories":["Kotlin"],"sub_categories":[],"readme":"# Immutable Collections Library for Kotlin\n\n[![Kotlin Alpha](https://kotl.in/badges/alpha.svg)](https://kotlinlang.org/docs/components-stability.html)\n[![JetBrains official project](https://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) \n[![GitHub license](https://img.shields.io/github/license/kotlin/kotlinx.collections.immutable)](LICENSE.txt) \n[![Build status](https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:KotlinTools_KotlinxCollectionsImmutable_Build_All)/statusIcon.svg)](https://teamcity.jetbrains.com/viewType.html?buildTypeId=KotlinTools_KotlinxCollectionsImmutable_Build_All)\n[![Maven Central](https://img.shields.io/maven-central/v/org.jetbrains.kotlinx/kotlinx-collections-immutable.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/org.jetbrains.kotlinx/kotlinx-collections-immutable)\n\nImmutable collection interfaces and implementation prototypes for Kotlin.\n\nThis is a multiplatform library providing implementations for `jvm`, `js`, `wasmJs`, `wasmWasi`\nand all [targets supported by the Kotlin/Native compiler](https://kotlinlang.org/docs/native-target-support.html).\n\nFor further details see the [proposal](proposal.md).\n\n## What's in this library\n### Interfaces and implementations\n\nThis library provides interfaces for immutable and persistent collections.\n\n#### Immutable collection interfaces    \n \n| Interface | Bases \n| ----------| ----- \n| `ImmutableCollection` | `Collection` |\n| `ImmutableList` | `ImmutableCollection`, `List` | \n| `ImmutableSet` | `ImmutableCollection`, `Set` | \n| `ImmutableMap` | `Map` |\n\n#### Persistent collection interfaces\n\n| Interface | Bases \n| ----------| ----- \n| `PersistentCollection` | `ImmutableCollection` | \n| `PersistentList` | `PersistentCollection`, `ImmutableList` | \n| `PersistentSet` | `PersistentCollection`, `ImmutableSet` | \n| `PersistentMap` | `ImmutableMap` |\n\n#### Persistent collection builder interfaces\n\n| Interface | Bases \n| ----------| ----- \n| `PersistentCollection.Builder` | `MutableCollection` | \n| `PersistentList.Builder` | `PersistentCollection.Builder`, `MutableList` | \n| `PersistentSet.Builder` | `PersistentCollection.Builder`, `MutableSet` | \n| `PersistentMap.Builder` | `MutableMap` |\n\n\nTo instantiate an empty persistent collection or a collection with the specified elements use the functions \n`persistentListOf`, `persistentSetOf`, and `persistentMapOf`.\n\nThe default implementations of `PersistentSet` and `PersistentMap`, which are returned by `persistentSetOf` and `persistentMapOf`,\npreserve the element insertion order during iteration. This comes at expense of maintaining more complex data structures.\nIf the order of elements doesn't matter, the more efficient implementations returned by the functions \n`persistentHashSetOf` and `persistentHashMapOf` can be used.\n\n### Operations\n\n#### toImmutableList/Set/Map\n\nConverts a read-only or mutable collection to an immutable one.\nIf the receiver is already immutable and has the required type, returns it as is.\n\n```kotlin\nfun Iterable\u003cT\u003e.toImmutableList(): ImmutableList\u003cT\u003e\nfun Iterable\u003cT\u003e.toImmutableSet(): ImmutableSet\u003cT\u003e\n```\n\n#### toPersistentList/Set/Map\n\nConverts a read-only or mutable collection to a persistent one.\nIf the receiver is already persistent and has the required type, returns it as is.\nIf the receiver is a builder of the required persistent collection type, calls `build` on it and returns the result.\n\n```kotlin\nfun Iterable\u003cT\u003e.toPersistentList(): PersistentList\u003cT\u003e\nfun Iterable\u003cT\u003e.toPersistentSet(): PersistentSet\u003cT\u003e\n```\n\n#### `+` and `-` operators\n\n`plus` and `minus` operators on persistent collections exploit their immutability\nand delegate the implementation to the collections themselves. \nThe operation is performed with persistence in mind: the returned immutable collection may share storage \nwith the original collection.\n\n```kotlin\nval newList = persistentListOf(\"a\", \"b\") + \"c\"\n// newList is also a PersistentList\n```\n\n\u003e **Note:** you need to import these operators from `kotlinx.collections.immutable` package\nin order for them to take the precedence over the ones from the \nstandard library.\n\n```kotlin\nimport kotlinx.collections.immutable.*\n```\n   \n#### Mutate\n\n`mutate` extension function simplifies quite common pattern of persistent collection modification: \nget a builder, apply some mutating operations on it, transform it back to a persistent collection:\n\n```kotlin\ncollection.builder().apply { some_actions_on(this) }.build()\n```\n    \nWith `mutate` it transforms to:\n\n```kotlin\ncollection.mutate { some_actions_on(it) }\n```\n\n## Using in your projects\n\n\u003e Note that the library is experimental and the API is subject to change.\n\nThe library is published to Maven Central repository.\n\nThe library depends on the Kotlin Standard Library of the version at least `1.9.21`.\n\n### Gradle\n\nAdd the Maven Central repository:\n\n```groovy\nrepositories {\n    mavenCentral()\n}\n```\n\nAdd the library to dependencies of the platform source set, e.g.:\n\n```groovy\nkotlin {\n    sourceSets {\n        commonMain {\n             dependencies {\n                 implementation(\"org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.8\")\n             }\n        }\n    }\n}\n```\n\n### Maven\n\nThe Maven Central repository is available for dependency lookup by default. \nAdd dependencies (you can also add other modules that you need):\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eorg.jetbrains.kotlinx\u003c/groupId\u003e\n    \u003cartifactId\u003ekotlinx-collections-immutable-jvm\u003c/artifactId\u003e\n    \u003cversion\u003e0.3.8\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Building from source\n\nYou can build and install artifacts to maven local with:\n\n    gradlew build install\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKotlin%2Fkotlinx.collections.immutable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKotlin%2Fkotlinx.collections.immutable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKotlin%2Fkotlinx.collections.immutable/lists"}