Align

beginner

The Align typeclass extends the Semialign typeclass with a value empty(), which acts as a unit in regards to align.

Main Combinators

empty()

returns an empty structure which can be used as either argument for align.

fun <A> empty(): Kind<F, A>


import arrow.core.extensions.*
import arrow.core.extensions.listk.align.align
import arrow.core.*

ListK.align().run {
    align(listOf("A", "B").k(), empty<String>())
}
// ListK(list=[Left(value=A), Left(value=B)])

Laws

Arrow provides AlignLaws in the form of test cases for internal verification of lawful instances and third party apps creating their own Align instances.

Creating your own Align instances

Arrow already provides Align instances for common datatypes (e.g. Option, ListK, MapK). See their implementations and accomanying testcases for reference.

See Deriving and creating custom typeclass

Additionally all instances of Align implement the Semialign typeclass directly since they are all subtypes of Semialign

Data types

Module Data types
arrow.core ListK, MapK, Option, SequenceK

Type Class Hierarchy