diff --git a/README.md b/README.md index 96ec1a42..b93d0332 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,8 @@ fun Iterable.toPersistentSet(): PersistentSet #### `+` 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 +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. ```kotlin @@ -90,8 +90,8 @@ val newList = persistentListOf("a", "b") + "c" ``` > **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. +> in order for them to take the precedence over the ones from the +> standard library. ```kotlin import kotlinx.collections.immutable.* @@ -112,6 +112,36 @@ With `mutate` it transforms to: collection.mutate { some_actions_on(it) } ``` +### Serialization + +Serialization modules allows you to apply custom immutable collection serializers, for example: + +```kotlin +@Serializable +private class MyCustomClass( + @Serializable(with = ImmutableMapSerializer::class) + val immutableMap: ImmutableMap +) +``` + +#### Collection Serializers + +| Serializer | Conversion method +|-------------------------------|------------------------- +| `ImmutableListSerializer` | `toImmutableList()` | +| `PersistentListSerializer` | `toPersistentList()` | +| `ImmutableSetSerializer` | `toImmutableSet()` | +| `PersistentSetSerializer` | `toPersistentSet()` | +| `PersistentHashSetSerializer` | `toPersistentHashSet()` | + +#### Map Serializers + +| Serializer | Conversion method +|-------------------------------|------------------------- +| `ImmutableMapSerializer` | `toImmutableMap()` | +| `PersistentMapSerializer` | `toPersistentMap()` | +| `PersistentHashMapSerializer` | `toPersistentHashMap()` | + ## Using in your projects > Note that the library is experimental and the API is subject to change. @@ -136,9 +166,10 @@ Add the library to dependencies of the platform source set, e.g.: kotlin { sourceSets { commonMain { - dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.7") - } + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.7") + implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable-serialization:0.3.7") + } } } } @@ -146,15 +177,23 @@ kotlin { ### Maven -The Maven Central repository is available for dependency lookup by default. +The Maven Central repository is available for dependency lookup by default. Add dependencies (you can also add other modules that you need): ```xml - - org.jetbrains.kotlinx - kotlinx-collections-immutable-jvm - 0.3.7 - + + + + org.jetbrains.kotlinx + kotlinx-collections-immutable-jvm + 0.3.7 + + + org.jetbrains.kotlinx + kotlinx-collections-immutable-serialization-jvm + 0.3.7 + + ``` ## Building from source