Align

cats.Align
See theAlign companion object
trait Align[F[_]] extends Serializable

Align supports zipping together structures with different shapes, holding the results from either or both structures in an Ior.

Must obey the laws in cats.laws.AlignLaws

Attributes

Companion
object
Source
Align.scala
Graph
Supertypes
trait Serializable
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def align[A, B](fa: F[A], fb: F[B]): F[Ior[A, B]]

Pairs elements of two structures along the union of their shapes, using Ior to hold the results.

Pairs elements of two structures along the union of their shapes, using Ior to hold the results.

Example:

scala> import cats.syntax.all._
scala> import cats.data.Ior
scala> Align[List].align(List(1, 2), List(10, 11, 12))
res0: List[Ior[Int, Int]] = List(Both(1,10), Both(2,11), Right(12))

Attributes

Source
Align.scala
def functor: Functor[F]

Attributes

Source
Align.scala

Concrete methods

def alignCombine[A : Semigroup](fa1: F[A], fa2: F[A]): F[A]

Align two structures with the same element, combining results according to their semigroup instances.

Align two structures with the same element, combining results according to their semigroup instances.

Example:

scala> import cats.syntax.all._
scala> Align[List].alignCombine(List(1, 2), List(10, 11, 12))
res0: List[Int] = List(11, 13, 12)

Attributes

Source
Align.scala
def alignMergeWith[A](fa1: F[A], fa2: F[A])(f: (A, A) => A): F[A]

Align two structures with the same element, combining results according to the given function.

Align two structures with the same element, combining results according to the given function.

Example:

scala> import cats.syntax.all._
scala> Align[List].alignMergeWith(List(1, 2), List(10, 11, 12))(_ + _)
res0: List[Int] = List(11, 13, 12)

Attributes

Source
Align.scala
def alignWith[A, B, C](fa: F[A], fb: F[B])(f: Ior[A, B] => C): F[C]

Combines elements similarly to align, using the provided function to compute the results.

Combines elements similarly to align, using the provided function to compute the results.

Example:

scala> import cats.syntax.all._
scala> Align[List].alignWith(List(1, 2), List(10, 11, 12))(_.mergeLeft)
res0: List[Int] = List(1, 2, 12)

Attributes

Source
Align.scala
def padZip[A, B](fa: F[A], fb: F[B]): F[(Option[A], Option[B])]

Same as align, but forgets from the type that one of the two elements must be present.

Same as align, but forgets from the type that one of the two elements must be present.

Example:

scala> import cats.syntax.all._
scala> Align[List].padZip(List(1, 2), List(10))
res0: List[(Option[Int], Option[Int])] = List((Some(1),Some(10)), (Some(2),None))

Attributes

Source
Align.scala
def padZipWith[A, B, C](fa: F[A], fb: F[B])(f: (Option[A], Option[B]) => C): F[C]

Same as alignWith, but forgets from the type that one of the two elements must be present.

Same as alignWith, but forgets from the type that one of the two elements must be present.

Example:

scala> import cats.syntax.all._
scala> Align[List].padZipWith(List(1, 2), List(10, 11, 12))(_ |+| _)
res0: List[Option[Int]] = List(Some(11), Some(13), Some(12))

Attributes

Source
Align.scala
def zipAll[A, B](fa: F[A], fb: F[B], a: A, b: B): F[(A, B)]

Pairs elements of two structures along the union of their shapes, using placeholders for missing values.

Pairs elements of two structures along the union of their shapes, using placeholders for missing values.

Example:

scala> import cats.syntax.all._
scala> Align[List].zipAll(List(1, 2), List(10, 11, 12), 20, 21)
res0: List[(Int, Int)] = List((1,10), (2,11), (20,12))

Attributes

Source
Align.scala