Skip to content
This repository was archived by the owner on Jan 24, 2025. It is now read-only.

Commit 0035b75

Browse files
Merge pull request #413 from kubukoz/diff-chain
Add Diff[Chain]
2 parents a34bac1 + cd9dbd9 commit 0035b75

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

cats/src/main/scala/com/softwaremill/diffx/cats/DiffCatsInstances.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.softwaremill.diffx.cats
22

3-
import cats.data.{NonEmptyChain, NonEmptyList, NonEmptyMap, NonEmptySet, NonEmptyVector}
3+
import cats.data.{Chain, NonEmptyChain, NonEmptyList, NonEmptyMap, NonEmptySet, NonEmptyVector}
44
import com.softwaremill.diffx.instances.{DiffForMap, DiffForSeq, DiffForSet}
55
import com.softwaremill.diffx.{Diff, MapLike, MapMatcher, SeqLike, SeqMatcher, SetLike, SetMatcher}
66

@@ -15,12 +15,22 @@ trait DiffCatsInstances {
1515
override def asSeq[A](c: NonEmptyList[A]): Seq[A] = c.toList
1616
}
1717

18+
implicit def diffChain[T: Diff](implicit
19+
seqMatcher: SeqMatcher[T],
20+
seqLike: SeqLike[Chain]
21+
): Diff[Chain[T]] =
22+
new DiffForSeq[Chain, T](Diff[T], seqMatcher, seqLike, "Chain")
23+
1824
implicit def diffNec[T: Diff](implicit
1925
seqMatcher: SeqMatcher[T],
2026
seqLike: SeqLike[NonEmptyChain]
2127
): Diff[NonEmptyChain[T]] =
2228
new DiffForSeq[NonEmptyChain, T](Diff[T], seqMatcher, seqLike, "NonEmptyChain")
2329

30+
implicit def chainIsLikeSeq: SeqLike[Chain] = new SeqLike[Chain] {
31+
override def asSeq[A](c: Chain[A]): Seq[A] = c.toList
32+
}
33+
2434
implicit def necIsLikeSeq: SeqLike[NonEmptyChain] = new SeqLike[NonEmptyChain] {
2535
override def asSeq[A](c: NonEmptyChain[A]): Seq[A] = c.toChain.toList
2636
}

cats/src/test/scala/com/softwaremill/diffx/cats/DiffxCatsTest.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class DiffxCatsTest extends AnyFreeSpec with Matchers {
1313
)
1414
}
1515

16+
"chain" in {
17+
compare(Chain(1), Chain(2)) shouldBe DiffResultObject(
18+
"Chain",
19+
Map("0" -> DiffResultValue(1, 2))
20+
)
21+
}
22+
1623
"nonEmptyChain" in {
1724
compare(NonEmptyChain.one(1), NonEmptyChain.one(2)) shouldBe DiffResultObject(
1825
"NonEmptyChain",

0 commit comments

Comments
 (0)