@@ -41,7 +41,7 @@ For persistent collection interfaces there shall be provided the following imple
4141* Avoiding defensive copying of collection passed as a parameter
4242 when you need an unchangeable snapshot and you're unsure whether the collection could be changed later.
4343
44- ```
44+ ``` kotlin
4545 class Query (val parameters : ImmutableList <Parameter >)
4646
4747 // or
@@ -105,13 +105,13 @@ It can be done by the following means:
105105
106106- chaining operations together
107107
108- ```
108+ ```kotlin
109109 collection = collection.add(element).add(anotherElement)
110110 ```
111111
112112- applying operations one by one
113113
114- ```
114+ ```kotlin
115115 collection += element
116116 collection += anotherElement
117117 ```
@@ -125,7 +125,7 @@ For example, `PersistentSet.Builder<T>` extends `MutableSet<T>`.
125125A builder can be obtained from a persistent collection with `builder()` method, and then that builder could be
126126transformed back to a persistent collection with its `build()` method.
127127
128- ```
128+ ```kotlin
129129val builder = persistentList.builder()
130130builder.removeAll { it.value > treshold }
131131if (builder.isEmpty()) {
@@ -274,17 +274,21 @@ avoiding memory allocations in modification operations leads to significant perf
274274Converts a read-only or mutable collection to immutable one.
275275If the receiver is already immutable and has the required type, returns it as is.
276276
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+ ```
279281
280282#### toPersistentList/Set/Map
281283
282284Converts a read-only or mutable collection to persistent one.
283285If the receiver is already persistent and has the required type, returns it as is.
284286If the receiver is a builder of the required persistent collection type, calls `build` on it and returns the result.
285287
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+ ```
288292
289293#### `+` and `-` operators
290294
@@ -295,11 +299,13 @@ If the receiver is a builder of the required persistent collection type, calls `
295299A quite common pattern with builders arises: get a builder, apply some mutating operations on it,
296300transform it back to an immutable collection:
297301
298- collection.builder().apply { some_actions_on(this) }.build()
302+ ```kotlin
303+ collection.builder().apply { some_actions_on(this) }.build()
304+ ```
299305
300306This pattern could be extracted to an extension function.
301307
302- ```
308+ ```kotlin
303309fun <T> PersitentList<T>.mutate(action: (MutableList<T>) -> Unit): PersitentList<T> =
304310 builder().apply { action(this) }.build()
305311```
0 commit comments