Skip to content

Commit

Permalink
Merge pull request #4676 from joroKr21/align-with
Browse files Browse the repository at this point in the history
Use alignWith in alignMergeWith
  • Loading branch information
danicheg authored Nov 16, 2024
2 parents 7a30dc2 + 0c7adab commit 02bfdf7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion core/src/main/scala/cats/Align.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ trait Align[F[_]] extends Serializable {
* }}}
*/
def alignMergeWith[A](fa1: F[A], fa2: F[A])(f: (A, A) => A): F[A] =
functor.map(align(fa1, fa2))(_.mergeWith(f))
alignWith(fa1, fa2)(_.mergeWith(f))

/**
* Same as `align`, but forgets from the type that one of the two elements must be present.
Expand Down
3 changes: 3 additions & 0 deletions laws/src/main/scala/cats/laws/AlignLaws.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ trait AlignLaws[F[_]] {
def alignWithConsistent[A, B, C](fa: F[A], fb: F[B], f: A Ior B => C): IsEq[F[C]] =
fa.alignWith(fb)(f) <-> fa.align(fb).map(f)

def alignMergeWithConsistent[A](fa1: F[A], fa2: F[A], f: (A, A) => A): IsEq[F[A]] =
fa1.alignMergeWith(fa2)(f) <-> fa1.align(fa2).map(_.mergeWith(f))

private def assoc[A, B, C](x: Ior[A, Ior[B, C]]): Ior[Ior[A, B], C] =
x match {
case Left(a) => Left(Left(a))
Expand Down
9 changes: 3 additions & 6 deletions laws/src/main/scala/cats/laws/discipline/AlignTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,9 @@ trait AlignTests[F[_]] extends Laws {
name = "align",
parent = None,
"align associativity" -> forAll(laws.alignAssociativity[A, B, C] _),
"align homomorphism" -> forAll { (fa: F[A], fb: F[B], f: A => C, g: B => D) =>
laws.alignHomomorphism[A, B, C, D](fa, fb, f, g)
},
"alignWith consistent" -> forAll { (fa: F[A], fb: F[B], f: A Ior B => C) =>
laws.alignWithConsistent[A, B, C](fa, fb, f)
}
"align homomorphism" -> forAll(laws.alignHomomorphism[A, B, C, D] _),
"alignWith consistent" -> forAll(laws.alignWithConsistent[A, B, C] _),
"alignMergeWith consistent" -> forAll(laws.alignMergeWithConsistent[A] _)
)
}

Expand Down

0 comments on commit 02bfdf7

Please sign in to comment.