split
Attempt to split the Iterable into the tail and the first element. Returns null
if the Iterable is empty, otherwise returns a Pair of the tail and the first element.
import arrow.core.*
import io.kotest.matchers.shouldBe
fun test() {
emptyList<Int>().split() shouldBe null
listOf("A", "B", "C").split() shouldBe Pair(listOf("B", "C"), "A")
}
Content copied to clipboard
attempt to split the computation, giving access to the first result.
import arrow.core.split
import io.kotest.matchers.shouldBe
fun test() {
sequenceOf("A", "B", "C").split()?.let { (tail, head) ->
head shouldBe "A"
tail.toList() shouldBe listOf("B", "C")
}
emptySequence<String>().split() shouldBe null
}
Content copied to clipboard