The Crosswalk
typeclass extends the Functor
and Foldable
typeclass with the possibility to traverse the
structure through an alignable functor.
fun <F, A, B> crosswalk(ALIGN: Align<F>, fa: (A) -> Kind<F, B>, a: Kind<T, A>): Kind<F, Kind<T, B>>
import arrow.core.extensions.*
import arrow.core.extensions.listk.crosswalk.crosswalk
import arrow.core.extensions.listk.align.align
import arrow.core.*
ListK.crosswalk().run {
crosswalk(ListK.align(), listOf("1:2:3:4:5", "6:7:8:9:10", "11:12").k()) {
it.split(":").k()
}
}
// [[11, 6, 1], [12, 7, 2], [8, 3], [9, 4], [10, 5]]
fun <F, A> sequenceL(ALIGN: Align<F>, tfa: Kind<T, Kind<F, A>>): Kind<F, Kind<T, A>>
import arrow.core.extensions.*
import arrow.core.extensions.listk.crosswalk.crosswalk
import arrow.core.extensions.listk.align.align
import arrow.core.*
ListK.crosswalk().run {
val lists = listOf(listOf(1, 2, 3, 4, 5).k(),
listOf(6, 7, 8, 9, 10).k(),
listOf(11, 12).k())
sequenceL(ListK.align(), lists.k())
}
// [[11, 6, 1], [12, 7, 2], [8, 3], [9, 4], [10, 5]]
Arrow provides CrosswalkLaws
in the form of test cases for internal verification of lawful instances and third party apps creating their own Crosswalk instances.
Crosswalk
instancesArrow already provides Crosswalk instances for common datatypes (e.g. Option, ListK). See their implementations and accompanying testcases for reference.
See Deriving and creating custom typeclass
Additionally all instances of Crosswalk
implement the Functor
and Foldable
typeclass directly.
Module | Data types |
arrow.core | Id, Ior, ListK, Option, SequenceK |
Do you like Arrow?
✖