@@ -41,7 +41,7 @@ For persistent collection interfaces there shall be provided the following imple
41
41
* Avoiding defensive copying of collection passed as a parameter
42
42
when you need an unchangeable snapshot and you're unsure whether the collection could be changed later.
43
43
44
- ```
44
+ ``` kotlin
45
45
class Query (val parameters : ImmutableList <Parameter >)
46
46
47
47
// or
@@ -105,13 +105,13 @@ It can be done by the following means:
105
105
106
106
- chaining operations together
107
107
108
- ```
108
+ ```kotlin
109
109
collection = collection.add(element).add(anotherElement)
110
110
```
111
111
112
112
- applying operations one by one
113
113
114
- ```
114
+ ```kotlin
115
115
collection += element
116
116
collection += anotherElement
117
117
```
@@ -125,7 +125,7 @@ For example, `PersistentSet.Builder<T>` extends `MutableSet<T>`.
125
125
A builder can be obtained from a persistent collection with `builder()` method, and then that builder could be
126
126
transformed back to a persistent collection with its `build()` method.
127
127
128
- ```
128
+ ```kotlin
129
129
val builder = persistentList.builder()
130
130
builder.removeAll { it.value > treshold }
131
131
if (builder.isEmpty()) {
@@ -274,17 +274,21 @@ avoiding memory allocations in modification operations leads to significant perf
274
274
Converts a read-only or mutable collection to immutable one.
275
275
If the receiver is already immutable and has the required type, returns it as is.
276
276
277
- fun Iterable<T>.toImmutableList(): ImmutableList<T>
278
- fun Iterable<T>.toImmutableSet(): ImmutableSet<T>
277
+ ```kotlin
278
+ fun Iterable<T>.toImmutableList(): ImmutableList<T>
279
+ fun Iterable<T>.toImmutableSet(): ImmutableSet<T>
280
+ ```
279
281
280
282
#### toPersistentList/Set/Map
281
283
282
284
Converts a read-only or mutable collection to persistent one.
283
285
If the receiver is already persistent and has the required type, returns it as is.
284
286
If the receiver is a builder of the required persistent collection type, calls `build` on it and returns the result.
285
287
286
- fun Iterable<T>.toPersistentList(): PersistentList<T>
287
- fun Iterable<T>.toPersistentSet(): PersistentSet<T>
288
+ ```kotlin
289
+ fun Iterable<T>.toPersistentList(): PersistentList<T>
290
+ fun Iterable<T>.toPersistentSet(): PersistentSet<T>
291
+ ```
288
292
289
293
#### `+` and `-` operators
290
294
@@ -295,11 +299,13 @@ If the receiver is a builder of the required persistent collection type, calls `
295
299
A quite common pattern with builders arises: get a builder, apply some mutating operations on it,
296
300
transform it back to an immutable collection:
297
301
298
- collection.builder().apply { some_actions_on(this) }.build()
302
+ ```kotlin
303
+ collection.builder().apply { some_actions_on(this) }.build()
304
+ ```
299
305
300
306
This pattern could be extracted to an extension function.
301
307
302
- ```
308
+ ```kotlin
303
309
fun <T> PersitentList<T>.mutate(action: (MutableList<T>) -> Unit): PersitentList<T> =
304
310
builder().apply { action(this) }.build()
305
311
```
0 commit comments