Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
makeevrserg committed Apr 18, 2024
1 parent 40b36e3 commit 3b0470c
Showing 1 changed file with 52 additions and 13 deletions.
65 changes: 52 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ 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
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
Expand All @@ -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.*
Expand All @@ -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<K, V>(
@Serializable(with = ImmutableMapSerializer::class)
val immutableMap: ImmutableMap<K, V>
)
```

#### 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.
Expand All @@ -136,25 +166,34 @@ 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")
}
}
}
}
```

### 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
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-collections-immutable-jvm</artifactId>
<version>0.3.7</version>
</dependency>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-collections-immutable-jvm</artifactId>
<version>0.3.7</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-collections-immutable-serialization-jvm</artifactId>
<version>0.3.7</version>
</dependency>
</dependencies>
```

## Building from source
Expand Down

0 comments on commit 3b0470c

Please sign in to comment.