unweave

fun <A, B> Iterable<A>.unweave(ffa: (A) -> Iterable<B>): List<B>

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) })
}

fun <A, B> Sequence<A>.unweave(ffa: (A) -> Sequence<B>): Sequence<B>

Fair conjunction. Similarly to interleave

import arrow.core.unweave

fun main() {
//sampleStart
val result = sequenceOf(1,2,3).unweave { i -> sequenceOf("$i, ${i + 1}") }
//sampleEnd
println(result.toList())
}