@@ -80,8 +80,8 @@ fun Iterable<T>.toPersistentSet(): PersistentSet<T>
80
80
#### ` + ` and ` - ` operators
81
81
82
82
` plus ` and ` minus ` operators on persistent collections exploit their immutability
83
- and delegate the implementation to the collections themselves.
84
- The operation is performed with persistence in mind: the returned immutable collection may share storage
83
+ and delegate the implementation to the collections themselves.
84
+ The operation is performed with persistence in mind: the returned immutable collection may share storage
85
85
with the original collection.
86
86
87
87
``` kotlin
@@ -90,8 +90,8 @@ val newList = persistentListOf("a", "b") + "c"
90
90
```
91
91
92
92
> ** Note:** you need to import these operators from ` kotlinx.collections.immutable ` package
93
- in order for them to take the precedence over the ones from the
94
- standard library.
93
+ > in order for them to take the precedence over the ones from the
94
+ > standard library.
95
95
96
96
``` kotlin
97
97
import kotlinx.collections.immutable.*
@@ -112,6 +112,36 @@ With `mutate` it transforms to:
112
112
collection.mutate { some_actions_on(it) }
113
113
```
114
114
115
+ ### Serialization
116
+
117
+ Serialization modules allows you to apply custom immutable collection serializers, for example:
118
+
119
+ ``` kotlin
120
+ @Serializable
121
+ private class MyCustomClass <K , V >(
122
+ @Serializable(with = ImmutableMapSerializer ::class )
123
+ val immutableMap : ImmutableMap <K , V >
124
+ )
125
+ ```
126
+
127
+ #### Collection Serializers
128
+
129
+ | Serializer | Conversion method
130
+ |-------------------------------|-------------------------
131
+ | ` ImmutableListSerializer ` | ` toImmutableList() ` |
132
+ | ` PersistentListSerializer ` | ` toPersistentList() ` |
133
+ | ` ImmutableSetSerializer ` | ` toImmutableSet() ` |
134
+ | ` PersistentSetSerializer ` | ` toPersistentSet() ` |
135
+ | ` PersistentHashSetSerializer ` | ` toPersistentHashSet() ` |
136
+
137
+ #### Map Serializers
138
+
139
+ | Serializer | Conversion method
140
+ |-------------------------------|-------------------------
141
+ | ` ImmutableMapSerializer ` | ` toImmutableMap() ` |
142
+ | ` PersistentMapSerializer ` | ` toPersistentMap() ` |
143
+ | ` PersistentHashMapSerializer ` | ` toPersistentHashMap() ` |
144
+
115
145
## Using in your projects
116
146
117
147
> Note that the library is experimental and the API is subject to change.
@@ -138,6 +168,7 @@ kotlin {
138
168
commonMain {
139
169
dependencies {
140
170
implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.8")
171
+ implementation("org.jetbrains.kotlinx:kotlinx-collections-immutable-serialization:0.3.8")
141
172
}
142
173
}
143
174
}
@@ -150,11 +181,19 @@ The Maven Central repository is available for dependency lookup by default.
150
181
Add dependencies (you can also add other modules that you need):
151
182
152
183
``` xml
153
- <dependency >
154
- <groupId >org.jetbrains.kotlinx</groupId >
155
- <artifactId >kotlinx-collections-immutable-jvm</artifactId >
156
- <version >0.3.8</version >
157
- </dependency >
184
+
185
+ <dependencies >
186
+ <dependency >
187
+ <groupId >org.jetbrains.kotlinx</groupId >
188
+ <artifactId >kotlinx-collections-immutable-jvm</artifactId >
189
+ <version >0.3.8</version >
190
+ </dependency >
191
+ <dependency >
192
+ <groupId >org.jetbrains.kotlinx</groupId >
193
+ <artifactId >kotlinx-collections-immutable-serialization-jvm</artifactId >
194
+ <version >0.3.8</version >
195
+ </dependency >
196
+ </dependencies >
158
197
```
159
198
160
199
## Building from source
0 commit comments