unweave
interleaves the elements produced by applying ffa to every element of this
Iterable.
import arrow.core.*
import io.kotest.matchers.shouldBe
fun test() {
val ints = listOf(1, 2)
val res = ints.unweave { i -> listOf(i, i + 1, i + 2) }
res shouldBe listOf(1, 2, 2, 3, 3, 4)
res shouldBe ints.interleave(ints.flatMap { listOf(it + 1, it + 2) })
}
Content copied to clipboard
Fair conjunction. Similarly to interleave
import arrow.core.unweave
fun main(args: Array<String>) {
//sampleStart
val result = sequenceOf(1,2,3).unweave { i -> sequenceOf("$i, ${i + 1}") }
//sampleEnd
println(result.toList())
}
Content copied to clipboard