//arrow-core/arrow.core/unalign

unalign

common fun <A, B> Iterable<Ior<A, B».unalign(): Pair<List<A>, List<B»

splits a union into its component parts.

import arrow.core.*

fun main(args: Array<String>) {
  //sampleStart
  val result =
   listOf(("A" to 1).bothIor(), ("B" to 2).bothIor(), "C".leftIor())
     .unalign()
  //sampleEnd
  println(result)
}

common inline fun <A, B, C> Iterable<C>.unalign(fa: (C) -> Ior<A, B>): Pair<List<A>, List<B»

after applying the given function, splits the resulting union shaped structure into its components parts

import arrow.core.*

fun main(args: Array<String>) {
  //sampleStart
  val result =
     listOf(1, 2, 3).unalign {
       it.leftIor()
     }
  //sampleEnd
  println(result)
}

common fun <A, B> Option<Ior<A, B».unalign(): Pair<Option<A>, Option<B»

inline fun <A, B, C> Option<C>.unalign(f: (C) -> Ior<A, B>): Pair<Option<A>, Option<B»

common fun <A, B> Sequence<Ior<A, B».unalign(): Pair<Sequence<A>, Sequence<B»

splits an union into its component parts.

import arrow.core.bothIor
import arrow.core.leftIor
import arrow.core.unalign

fun main(args: Array<String>) {
  //sampleStart
  val result = sequenceOf(("A" to 1).bothIor(), ("B" to 2).bothIor(), "C".leftIor()).unalign()
  //sampleEnd
  println("(${result.first.toList()}, ${result.second.toList()})")
}

common fun <A, B, C> Sequence<C>.unalign(fa: (C) -> Ior<A, B>): Pair<Sequence<A>, Sequence<B»

after applying the given function, splits the resulting union shaped structure into its components parts

import arrow.core.leftIor
import arrow.core.unalign

fun main(args: Array<String>) {
  //sampleStart
  val result = sequenceOf(1, 2, 3).unalign { it.leftIor() }
  //sampleEnd
  println("(${result.first.toList()}, ${result.second.toList()})")
}

common fun <K, A, B> Map<K, Ior<A, B».unalign(): Pair<Map<K, A>, Map<K, B»

Splits a union into its component parts.

import arrow.core.*

fun main(args: Array<String>) {
  //sampleStart
  val result =
   mapOf(
     "first" to ("A" to 1).bothIor(),
     "second" to ("B" to 2).bothIor(),
     "third" to "C".leftIor()
   ).unalign()
  //sampleEnd
  println(result)
}

common fun <K, A, B, C> Map<K, C>.unalign(fa: (Map.Entry<K, C>) -> Ior<A, B>): Pair<Map<K, A>, Map<K, B»

after applying the given function, splits the resulting union shaped structure into its components parts

import arrow.core.*

fun main(args: Array<String>) {
  //sampleStart
  val result =
     mapOf("1" to 1, "2" to 2, "3" to 3)
       .unalign { it.leftIor() }
  //sampleEnd
  println(result)
}

Do you like Arrow?

Arrow Org
<