diff --git a/.gitignore b/.gitignore index 5564fa0a305..7b110e04948 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,5 @@ dist generated .next .teamcity/*.iml +.idea/misc.xml +.idea/vcs.xml diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 3fa0c744367..00000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index bafeaf22976..00000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/docs/topics/set-operations.md b/docs/topics/set-operations.md index ba66f40e9f9..4c745b33d0c 100644 --- a/docs/topics/set-operations.md +++ b/docs/topics/set-operations.md @@ -5,12 +5,8 @@ or subtracting collections from each other. To merge two collections into one, use the [`union()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/union.html) function. It can be used in the infix form `a union b`. -Note that for ordered collections the order of the operands is important: in the resulting collection, the elements of the -first operand go before the elements of the second. - -To find an intersection between two collections (elements present in both of them), use [`intersect()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/intersect.html). -To find collection elements not present in another collection, use [`subtract()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/subtract.html). -Both these functions can be called in the infix form as well, for example, `a intersect b`. +Note that for ordered collections the order of the operands is important. In the resulting collection, the elements of the +first operand go before the elements of the second: ```kotlin fun main() { @@ -19,7 +15,20 @@ fun main() { println(numbers union setOf("four", "five")) println(setOf("four", "five") union numbers) + // output according to the order +//sampleEnd +} +``` +{kotlin-runnable="true" kotlin-min-compiler-version="1.3"} +To find an intersection between two collections (elements present in both of them), use [`intersect()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/intersect.html). +To find collection elements not present in another collection, use [`subtract()`](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/subtract.html). +Both these functions can be called in the infix form as well, for example, `a intersect b`: + +```kotlin +fun main() { +//sampleStart + val numbers = setOf("one", "two", "three") println(numbers intersect setOf("two", "one")) println(numbers subtract setOf("three", "four")) println(numbers subtract setOf("four", "three")) @@ -47,7 +56,7 @@ fun main() { You can also apply `union()`, `intersect()`, and `subtract()` to `List`. However, their result is _always_ a `Set`, even on lists. In this result, all the duplicate elements are merged into one -and the index access is not available. +and the index access is not available: ```kotlin fun main() {