All Projects → Kotlin → Kotlinx.collections.immutable

Kotlin / Kotlinx.collections.immutable

Licence: apache-2.0
Immutable persistent collections for Kotlin

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kotlinx.collections.immutable

rrbit-js
No description or website provided.
Stars: ✭ 11 (-97.63%)
Mutual labels:  immutable, collections
Immutable
Immutable collections for Go
Stars: ✭ 392 (-15.7%)
Mutual labels:  immutable, collections
Polychrome
🎨 Easy color manipulation in ~2kb (gzipped)
Stars: ✭ 286 (-38.49%)
Mutual labels:  immutable
Deep Learning Resources
由淺入深的深度學習資源 Collection of deep learning materials for everyone
Stars: ✭ 422 (-9.25%)
Mutual labels:  collections
Immer
Create the next immutable state by mutating the current one
Stars: ✭ 21,756 (+4578.71%)
Mutual labels:  immutable
React Antd
基于react + redux + immutable + less + ES6/7 + webpack2.0 + fetch + react-router + antd实现的SPA后台管理系统模板
Stars: ✭ 321 (-30.97%)
Mutual labels:  immutable
Stream Parser
⚡ PHP7 / Laravel Multi-format Streaming Parser
Stars: ✭ 391 (-15.91%)
Mutual labels:  collections
Fpp
Functional PHP Preprocessor - Generate Immutable Data Types
Stars: ✭ 282 (-39.35%)
Mutual labels:  immutable
Easy Peasy
Vegetarian friendly state for React
Stars: ✭ 4,525 (+873.12%)
Mutual labels:  immutable
For Data Science Beginners
Set of 📝 with 🔗 to help those who are Data Science beginners 🤖
Stars: ✭ 355 (-23.66%)
Mutual labels:  collections
Laravel Helpers
An extensive set of Laravel framework helper functions and collection macros.
Stars: ✭ 407 (-12.47%)
Mutual labels:  collections
Capsule
The Capsule Hash Trie Collections Library
Stars: ✭ 350 (-24.73%)
Mutual labels:  immutable
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (-30.97%)
Mutual labels:  collections
Observable Membrane
A Javascript Membrane implementation using Proxies to observe mutation on an object graph
Stars: ✭ 315 (-32.26%)
Mutual labels:  immutable
Ewig
The eternal text editor — Didactic Ersatz Emacs to show immutable data-structures and the single-atom architecture
Stars: ✭ 422 (-9.25%)
Mutual labels:  immutable
Qframe
Immutable data frame for Go
Stars: ✭ 282 (-39.35%)
Mutual labels:  immutable
Data Structures
Go datastructures.
Stars: ✭ 336 (-27.74%)
Mutual labels:  immutable
Awesomearticles
🗃 收集看到的内容特别棒的技术文章并会配有一段个人短评
Stars: ✭ 383 (-17.63%)
Mutual labels:  collections
Koazee
A StreamLike, Immutable, Lazy Loading and smart Golang Library to deal with slices.
Stars: ✭ 446 (-4.09%)
Mutual labels:  immutable
Dinero.js
Create, calculate, and format money in JavaScript and TypeScript.
Stars: ✭ 5,286 (+1036.77%)
Mutual labels:  immutable

Immutable Collections Library for Kotlin

JetBrains incubator project GitHub license Download

Immutable collection interfaces and implementation prototypes for Kotlin.

This is a multiplatform library providing implementations for jvm, js, mingwX64, linuxX64, macosX64, iosX64, iosArm64, iosArm32 Kotlin targets.

For further details see the proposal.

What's in this library

Interfaces and implementations

This library provides interfaces for immutable and persistent collections.

Immutable collection interfaces

Interface Bases
ImmutableCollection Collection
ImmutableList ImmutableCollection, List
ImmutableSet ImmutableCollection, Set
ImmutableMap Map

Persistent collection interfaces

Interface Bases
PersistentCollection ImmutableCollection
PersistentList PersistentCollection, ImmutableList
PersistentSet PersistentCollection, ImmutableSet
PersistentMap ImmutableMap

Persistent collection builder interfaces

Interface Bases
PersistentCollection.Builder MutableCollection
PersistentList.Builder PersistentCollection.Builder, MutableList
PersistentSet.Builder PersistentCollection.Builder, MutableSet
PersistentMap.Builder MutableMap

To instantiate an empty persistent collection or a collection with the specified elements use the functions persistentListOf, persistentSetOf, and persistentMapOf.

The default implementations of PersistentSet and PersistentMap, which are returned by persistentSetOf and persistentMapOf, preserve the element insertion order during iteration. This comes at expense of maintaining more complex data structures. If the order of elements doesn't matter, the more efficient implementations returned by the functions persistentHashSetOf and persistentHashMapOf can be used.

Operations

toImmutableList/Set/Map

Converts a read-only or mutable collection to an immutable one. If the receiver is already immutable and has the required type, returns it as is.

fun Iterable<T>.toImmutableList(): ImmutableList<T>
fun Iterable<T>.toImmutableSet(): ImmutableSet<T>

toPersistentList/Set/Map

Converts a read-only or mutable collection to a persistent one. If the receiver is already persistent and has the required type, returns it as is. If the receiver is a builder of the required persistent collection type, calls build on it and returns the result.

fun Iterable<T>.toPersistentList(): PersistentList<T>
fun Iterable<T>.toPersistentSet(): PersistentSet<T>

+ and - operators

plus and minus operators on persistent collections exploit their immutability and delegate the implementation to the collections themselves. The operation is performed with persistence in mind: the returned immutable collection may share storage with the original collection.

val newList = persistentListOf("a", "b") + "c"
// newList is also a PersistentList

Note: you need to import these operators from kotlinx.collections.immutable package in order for them to take the precedence over the ones from the standard library.

import kotlinx.collections.immutable.*

Mutate

mutate extension function simplifies quite common pattern of persistent collection modification: get a builder, apply some mutating operations on it, transform it back to a persistent collection:

collection.builder().apply { some_actions_on(this) }.build()

With mutate it transforms to:

collection.mutate { some_actions_on(it) }

Using in your projects

Note that the library is experimental and the API is subject to change.

The library is published to kotlinx bintray repository and available in jcenter too.

The library depends on the Kotlin Standard Library of the version at least 1.4.0.

Gradle

Add the bintray repository:

repositories {
    jcenter()
}

In multiplatform projects add the following dependency to the common source set:

kotlin {
    sourceSets {
        commonMain {
             dependencies {
                 implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.3")
             }
        }
    }
}

To use the library in a JVM-only project add the platform to the artifact name, e.g.:

implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable-jvm:0.3.3")

Maven

Add the bintray repository to <repositories> section:

<repository>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <id>jcenter</id>
    <name>jcenter</name>
    <url>https://jcenter.bintray.com/</url>
</repository>

Add dependencies (you can also add other modules that you need):

<dependency>
    <groupId>org.jetbrains.kotlinx</groupId>
    <artifactId>kotlinx-collections-immutable-jvm</artifactId>
    <version>0.3.3</version>
</dependency>

Building from source

ℹ️ To build this project you will need to have a path to JDK 6 specified with the JDK_6 environment variable or gradle property. For the local development purposes any JDK newer than that can be used instead.

You can build and install artifacts to maven local with:

gradlew build install
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].