Add Regex splitToSequence samples

This commit is contained in:
Abduqodiri Qurbonzoda
2021-07-23 13:29:04 +03:00
committed by Space
parent e691de6e4c
commit d7b10f31b4
8 changed files with 30 additions and 0 deletions
@@ -52,4 +52,16 @@ class Regexps {
val names = matches.map { it.groupValues[1] }.joinToString()
assertPrints(names, "Alice, Bob, Eve")
}
@Sample
fun splitToSequence() {
val colors = "green, red , brown&blue, orange, pink&green"
val regex = "[,\\s]+".toRegex()
val mixedColor = regex.splitToSequence(colors)
.onEach { println(it) }
.firstOrNull { it.contains('&') }
assertPrints(mixedColor, "brown&blue")
}
}
@@ -495,4 +495,16 @@ class Strings {
assertPrints("abc".toBooleanStrictOrNull(), "null")
}
@Sample
fun splitToSequence() {
val colors = "green, red , brown&blue, orange, pink&green"
val regex = "[,\\s]+".toRegex()
val mixedColor = colors.splitToSequence(regex)
.onEach { println(it) }
.firstOrNull { it.contains('&') }
assertPrints(mixedColor, "brown&blue")
}
}