Add Regex splitToSequence samples
This commit is contained in:
committed by
Space
parent
e691de6e4c
commit
d7b10f31b4
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user