Search

arrow-core-data / arrow.typeclasses / Bitraverse

Bitraverse

interface Bitraverse<F> : Bifunctor<F>, Bifoldable<F>

The type class Bitraverse defines the behaviour of two separetes Traverse over a data type.

Every instance of Bitraverse<F> must contains the next functions:

Bitraverse

Bitraverse perfoms aTraverse over both side of the Data type which is Bifoldable.


import arrow.core.*
import arrow.core.extensions.option.applicative.applicative
import arrow.core.extensions.*
import arrow.core.extensions.tuple2.bitraverse.bitraverse
fun main() {
//sampleStart
 val f: (Int) -> Option<Int> = { Some(it + 1) }
 val g: (Int) -> Option<Int> = { Some(it * 3) }

 val tuple = Tuple2(1, 2)
 val bitraverseResult = tuple.bitraverse(Option.applicative(), f, g)
 //sampleEnd
 println(bitraverseResult)
}

Bisequence

Bisequence invert the original structure F<G<A,B>> to G<F<A>,F<B>>


import arrow.core.*
import arrow.core.extensions.*
import arrow.core.extensions.option.applicative.applicative
import arrow.core.extensions.tuple2.bitraverse.bisequence
fun main() {
 //sampleStart
 val tuple = Tuple2(Some(1), Some(2))
 val sequenceResult = tuple.bisequence(Option.applicative())
//sampleEnd
 println(sequenceResult)
}

Functions

bimap Maps both types of Kind2.open fun <A, B, C, D> Kind2<F, A, B>.bimap(f: (A) -> C, g: (B) -> D): Kind2<F, C, D>
bisequence open fun <G, A, B> Kind2<F, Kind<G, A>, Kind<G, B>>.bisequence(AP: Applicative<G>): Kind<G, Kind2<F, A, B>>
bitraverse abstract fun <G, A, B, C, D> Kind2<F, A, B>.bitraverse(AP: Applicative<G>, f: (A) -> Kind<G, C>, g: (B) -> Kind<G, D>): Kind<G, Kind2<F, C, D>>

Type Class Hierarchy