separateEither

Separate the inner Either values into the Either.Left and Either.Right.

import arrow.core.*
import io.kotest.matchers.shouldBe

fun test() {
listOf("A".left(), 2.right(), "C".left(), 4.right())
.separateEither() shouldBe Pair(listOf("A", "C"), listOf(2, 4))
}

inline fun <T, A, B> Iterable<T>.separateEither(f: (T) -> Either<A, B>): Pair<List<A>, List<B>>

Applies a function f to each element and returns a pair of arrays: the first one made of those values returned by f that were wrapped in Either.Left, and the second one made of those wrapped in Either.Right.

fun test() {
listOf(1, 2, 3, 4)
.separateEither {
if (it % 2 == 0) "even: $it".right() else "odd: $it".left()
} shouldBe Pair(listOf("odd: 1", "odd: 3"), listOf("even: 2", "even: 4"))
}

Separate the inner Either values into the Either.Left and Either.Right.

Receiver

Iterable of Either

Return

a tuple containing Sequence with Either.Left and another Sequence with its Either.Right values.