Skip to content
This repository has been archived by the owner on Jul 25, 2019. It is now read-only.
/ collekt Public archive

Persistent (immutable) collections for Kotlin

License

Notifications You must be signed in to change notification settings

jcornaz/collekt

Repository files navigation

Collekt

License Project status JitPack Build Status Quality gate

Persistent collections for Kotlin

The goal of this library is to provide a kotlin API for using persistent (immutable) collections, backed by the fastest known 3rd party implementation.

Current state of the project

This library is discontinued. And no support will be provided. I encourage you to use kotlinx.collections.immutable instead.

I created this library, mainly because no other available library was both nice to use from Kotlin and efficient (with state-of-the-art implementations).

But the developement of kotlinx.collections.immutable started again, and:

  • they published a version which is no longer backed by PCollections
  • they benchmarked and improved performances of their implementation
  • they used state-of-the-art algorithms
  • they plan to support Kotlin mutliplatform and they can do it more easily and reliably than I could.

Whith all of that I don't think collekt has much more value than kotlinx.collections.immutable. So I prefer invest my time on the developement kwik and other more valuable open source projects (maybe even kotlinx.collections.immutable).

Features

Always get the fastest implementation available, without the need to refactor your code

Collekt doesn't implement the persistent data-structure itself. It is always delegated to an open-source 3rd party.

In order to choose the actual implementation Collekt do performance tests an choose the fastest implementation.

If performance tests show that an new implementation is faster, then the actual implementation will be delegated to the new faster one. That way, as a user of Collekt, you only have to update the version of Collekt to get the fastest state-of-the-art persistent collection. And as the api stay the same, swapping to a faster implementation do not incur any refactoring overhead.

The current implementations are delegated to:

Platform Library Author
Java (8+) Paguro Glen K. Peterson
JavaScript Kotlin standard library JetBrains

Usage

The Persistent interfaces provide + and - operator aside other useful methods.

Usage is pretty straight forward if you're used to persistent data structure. Mutation are provided in the form of operator/functions which return a new instance with the operation applied.

val list1 = persistentListOf("Hello", "world")
val list2 = list1 - "world"
val list3 = list2 + "everybody"
val list4 = list3.with(1, "you")

println(list1) // ["Hello", "world"]
println(list2) // ["Hello"]
println(list3) // ["Hello", "everybody"]
println(list4) // ["Hello", "you"]

In most cases it will look exactly the same as if you'd use the standard library. But unlike the + and - operator of the standard library, the collections are not copied, and most of the data is shared making them much faster and less memory consuming.

How to get it

If you want to test the project in its current state, you can get the artifacts for maven or gradle from Jitpack:

repositories {
    jcenter()
    maven { url 'https://jitpack.io' }
}

dependencies {
    
    // For Java (JDK 8+)
    compile 'com.github.jcornaz.collekt:collekt-core-jvm:0.0.3'
            
    // For javascript (implementations are not efficient yet)
    compile 'com.github.jcornaz.collekt:collekt-core-js:0.0.3'
        
    // For common module
    compile 'com.github.jcornaz.collekt:collekt-core-common:0.0.3'
}

Implementation libraries

The current known challengers for a JVM implementation are:

The following libraries are not eligible because they are discontinued and/or don't support null values:

For Javascript the only known challenger is:

If you know another fast self-contained jvm or javascript implementation, please submit an issue.