diff --git a/cats/src/main/scala/com/softwaremill/diffx/cats/DiffCatsInstances.scala b/cats/src/main/scala/com/softwaremill/diffx/cats/DiffCatsInstances.scala index 1508438c..02cfa1e2 100644 --- a/cats/src/main/scala/com/softwaremill/diffx/cats/DiffCatsInstances.scala +++ b/cats/src/main/scala/com/softwaremill/diffx/cats/DiffCatsInstances.scala @@ -1,6 +1,6 @@ package com.softwaremill.diffx.cats -import cats.data.{NonEmptyChain, NonEmptyList, NonEmptyMap, NonEmptySet, NonEmptyVector} +import cats.data.{Chain, NonEmptyChain, NonEmptyList, NonEmptyMap, NonEmptySet, NonEmptyVector} import com.softwaremill.diffx.instances.{DiffForMap, DiffForSeq, DiffForSet} import com.softwaremill.diffx.{Diff, MapLike, MapMatcher, SeqLike, SeqMatcher, SetLike, SetMatcher} @@ -15,12 +15,22 @@ trait DiffCatsInstances { override def asSeq[A](c: NonEmptyList[A]): Seq[A] = c.toList } + implicit def diffChain[T: Diff](implicit + seqMatcher: SeqMatcher[T], + seqLike: SeqLike[Chain] + ): Diff[Chain[T]] = + new DiffForSeq[Chain, T](Diff[T], seqMatcher, seqLike, "Chain") + implicit def diffNec[T: Diff](implicit seqMatcher: SeqMatcher[T], seqLike: SeqLike[NonEmptyChain] ): Diff[NonEmptyChain[T]] = new DiffForSeq[NonEmptyChain, T](Diff[T], seqMatcher, seqLike, "NonEmptyChain") + implicit def chainIsLikeSeq: SeqLike[Chain] = new SeqLike[Chain] { + override def asSeq[A](c: Chain[A]): Seq[A] = c.toList + } + implicit def necIsLikeSeq: SeqLike[NonEmptyChain] = new SeqLike[NonEmptyChain] { override def asSeq[A](c: NonEmptyChain[A]): Seq[A] = c.toChain.toList } diff --git a/cats/src/test/scala/com/softwaremill/diffx/cats/DiffxCatsTest.scala b/cats/src/test/scala/com/softwaremill/diffx/cats/DiffxCatsTest.scala index a830988b..48ee95e0 100644 --- a/cats/src/test/scala/com/softwaremill/diffx/cats/DiffxCatsTest.scala +++ b/cats/src/test/scala/com/softwaremill/diffx/cats/DiffxCatsTest.scala @@ -13,6 +13,13 @@ class DiffxCatsTest extends AnyFreeSpec with Matchers { ) } + "chain" in { + compare(Chain(1), Chain(2)) shouldBe DiffResultObject( + "Chain", + Map("0" -> DiffResultValue(1, 2)) + ) + } + "nonEmptyChain" in { compare(NonEmptyChain.one(1), NonEmptyChain.one(2)) shouldBe DiffResultObject( "NonEmptyChain",