Add samples for partition
This commit is contained in:
@@ -146,6 +146,13 @@ class Arrays {
|
||||
val array = arrayOf(1 to 'a', 2 to 'b', 3 to 'c')
|
||||
assertPrints(array.unzip(), "([1, 2, 3], [a, b, c])")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun partitionArrayOfPrimitives() {
|
||||
val array = intArrayOf(1, 2, 3, 4, 5)
|
||||
val partition = array.partition { it % 2 == 0 }
|
||||
assertPrints(partition, "([2, 4], [1, 3, 5])")
|
||||
}
|
||||
}
|
||||
|
||||
class ContentOperations {
|
||||
|
||||
@@ -71,5 +71,18 @@ class Iterables {
|
||||
val result = listA.zip(listB) { a, b -> "$a$b" }
|
||||
assertPrints(result, "[a1, b2, c3]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun partition() {
|
||||
data class Person(val name: String, val age: Int) {
|
||||
override fun toString(): String {
|
||||
return "$name - $age"
|
||||
}
|
||||
}
|
||||
|
||||
val list = listOf(Person("Tom", 18), Person("Andy", 32), Person("Sarah", 22))
|
||||
val result = list.partition { it.age < 30 }
|
||||
assertPrints(result, "([Tom - 18, Sarah - 22], [Andy - 32])")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -228,6 +228,13 @@ class Sequences {
|
||||
val result = sequenceA.zip(sequenceB) { a, b -> "$a/$b" }
|
||||
assertPrints(result.take(4).toList(), "[a/1, b/3, c/7, d/15]")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun partition() {
|
||||
val sequence = sequenceOf(1, 2, 3, 4, 5)
|
||||
val result = sequence.partition { it % 2 == 0 }
|
||||
assertPrints(result, "([2, 4], [1, 3, 5])")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -170,6 +170,13 @@ class Strings {
|
||||
assertPrints(result, "{b=98, o=111, n=110, e=101, =32, j=106, u=117, r=114, é=233}")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun partition() {
|
||||
val string = "Hello"
|
||||
val result = string.partition { it == 'l' }
|
||||
assertPrints(result, "(ll, Heo)")
|
||||
}
|
||||
|
||||
@Sample
|
||||
fun stringToByteArray() {
|
||||
val charset = Charsets.UTF_8
|
||||
|
||||
Reference in New Issue
Block a user