Skip to content

Commit 47256b5

Browse files
committed
Update readme and examples
1 parent cf6347e commit 47256b5

File tree

1 file changed

+59
-23
lines changed

1 file changed

+59
-23
lines changed

README.md

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,77 @@ For further details see the [proposal](proposal.md).
99
## What's in this library
1010
### Interfaces and implementations
1111

12-
This library provides interfaces for immutable persistent collections:
13-
14-
| Interface | Bases | Implementations |
15-
| ----------| ----- | --------------- |
16-
| `ImmutableCollection` | `Collection`
17-
| `ImmutableList` | `ImmutableCollection`, `List` | `immutableListOf` |
18-
| `ImmutableSet` | `ImmutableCollection`, `Set` | `immutableSetOf`, `immutableHashSetOf` |
19-
| `ImmutableMap` | `Map` | `immutableMapOf`, `immutableHashMapOf` |
20-
21-
The default implementations of `ImmutableSet` and `ImmutableMap`, which are returned by `immutableSetOf` and `immutableMapOf`
12+
This library provides interfaces for immutable and persistent collections.
13+
14+
#### Immutable collection interfaces
15+
16+
| Interface | Bases
17+
| ----------| -----
18+
| `ImmutableCollection` | `Collection` |
19+
| `ImmutableList` | `ImmutableCollection`, `List` |
20+
| `ImmutableSet` | `ImmutableCollection`, `Set` |
21+
| `ImmutableMap` | `Map` |
22+
23+
#### Persistent collection interfaces
24+
25+
| Interface | Bases
26+
| ----------| -----
27+
| `PersistentCollection` | `ImmutableCollection` |
28+
| `PersistentList` | `PersistentCollection`, `ImmutableList` |
29+
| `PersistentSet` | `PersistentCollection`, `ImmutableSet` |
30+
| `PersistentMap` | `ImmutableMap` |
31+
32+
#### Persistent collection builder interfaces
33+
34+
| Interface | Bases
35+
| ----------| -----
36+
| `PersistentCollection.Builder` | `MutableCollection` |
37+
| `PersistentList.Builder` | `PersistentCollection.Builder`, `MutableList` |
38+
| `PersistentSet.Builder` | `PersistentCollection.Builder`, `MutableSet` |
39+
| `PersistentMap.Builder` | `MutableMap` |
40+
41+
42+
To instantiate an empty persistent collection or a collection with the specified elements the functions
43+
`persistentListOf`, `persistentSetOf`, and `persistentMapOf` can be used.
44+
45+
The default implementations of `PersistentSet` and `PersistentMap`, which are returned by `persistentSetOf` and `persistentMapOf`,
2246
preserve the element insertion order during iteration. This comes at expense of maintaining more complex data structures.
23-
If the order of elements doesn't matter, more efficient `immutableHashSetOf` and `immutableHashMapOf` could be used.
47+
If the order of elements doesn't matter, the more efficient implementations returned by the functions
48+
`persistentHashSetOf` and `persistentHashMapOf` could be used.
2449

2550
### Operations
2651

2752
#### toImmutableList/Set/Map
53+
2854
Converts a read-only or mutable collection to an immutable one.
29-
If the receiver is already immutable and has the required type, returns itself.
55+
If the receiver is already immutable and has the required type, returns it as is.
3056

3157
```kotlin
3258
fun Iterable<T>.toImmutableList(): ImmutableList<T>
3359
fun Iterable<T>.toImmutableSet(): ImmutableSet<T>
3460
```
3561

62+
#### toPersistentList/Set/Map
63+
64+
Converts a read-only or mutable collection to a persistent one.
65+
If the receiver is already persistent and has the required type, returns it as is.
66+
If the receiver is a builder of the required persistent collection type, calls `build` on it and returns the result.
67+
68+
```kotlin
69+
fun Iterable<T>.toPersistentList(): PersistentList<T>
70+
fun Iterable<T>.toPersistentSet(): PersistentSet<T>
71+
```
72+
3673
#### `+` and `-` operators
3774

38-
`plus` and `minus` operators on immutable collections exploit their immutability
75+
`plus` and `minus` operators on persistent collections exploit their immutability
3976
and delegate the implementation to the collections themselves.
4077
The operation is performed with persistence in mind: the returned immutable collection may share storage
4178
with the original collection.
4279

4380
```kotlin
44-
val newList = immutableListOf("a", "b") + "c"
45-
// newList is also ImmutableList
81+
val newList = persistentListOf("a", "b") + "c"
82+
// newList is also a PersistentList
4683
```
4784

4885
> **Note:** you need to import these operators from `kotlinx.collections.immutable` package
@@ -55,8 +92,8 @@ import kotlinx.collections.immutable.*
5592

5693
#### Mutate
5794

58-
`mutate` extension function simplifies quite common pattern of immutable collection modification:
59-
get a builder, apply some mutating operations on it, transform it back to an immutable collection:
95+
`mutate` extension function simplifies quite common pattern of persistent collection modification:
96+
get a builder, apply some mutating operations on it, transform it back to a persistent collection:
6097

6198
```kotlin
6299
collection.builder().apply { some_actions_on(this) }.build()
@@ -70,12 +107,11 @@ collection.mutate { some_actions_on(it) }
70107

71108
## Using in your projects
72109

73-
> Note that these libraries are experimental and are subject to change.
110+
> Note that the library is experimental and the API is subject to change.
74111
75-
The libraries are published to [kotlinx](https://bintray.com/kotlin/kotlinx/kotlinx.collections.immutable) bintray repository.
112+
The library is published to [kotlinx](https://bintray.com/kotlin/kotlinx/kotlinx.collections.immutable) bintray repository.
76113

77-
These libraries require kotlin compiler version to be at least `1.1.0` and
78-
require kotlin runtime of the same version as a dependency.
114+
The library depends on the Kotlin Standard Library of the version at least `1.3.30`.
79115

80116
### Maven
81117

@@ -98,7 +134,7 @@ Add dependencies (you can also add other modules that you need):
98134
<dependency>
99135
<groupId>org.jetbrains.kotlinx</groupId>
100136
<artifactId>kotlinx-collections-immutable</artifactId>
101-
<version>0.1</version>
137+
<version>0.2</version>
102138
</dependency>
103139
```
104140

@@ -117,7 +153,7 @@ repositories {
117153
Add the dependency:
118154

119155
```groovy
120-
compile 'org.jetbrains.kotlinx:kotlinx-collections-immutable:0.1'
156+
compile 'org.jetbrains.kotlinx:kotlinx-collections-immutable:0.2'
121157
```
122158

123159

0 commit comments

Comments
 (0)