partition

Splits the original char sequence into pair of char sequences, where first char sequence contains characters for which predicate yielded true, while second char sequence contains characters for which predicate yielded false.

Since Kotlin

1.0

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   fun isVowel(c: Char) = "aeuio".contains(c, ignoreCase = true)
val string = "Discussion"
val result = string.partition(::isVowel)
println(result) // (iuio, Dscssn) 
   //sampleEnd
}

inline fun String.partition(predicate: (Char) -> Boolean): Pair<String, String>(source)

Splits the original string into pair of strings, where first string contains characters for which predicate yielded true, while second string contains characters for which predicate yielded false.

Since Kotlin

1.0

Samples

import java.util.Locale
import kotlin.test.*

fun main() { 
   //sampleStart 
   fun isVowel(c: Char) = "aeuio".contains(c, ignoreCase = true)
val string = "Discussion"
val result = string.partition(::isVowel)
println(result) // (iuio, Dscssn) 
   //sampleEnd
}