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

Commit a666122

Browse files
committed
Setting version to 0.4.0
1 parent 5777727 commit a666122

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

README.md

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The library is published for Scala 2.12 and 2.13.
1313
## Table of contents
1414
- [goals of the project](#goals-of-the-project)
1515
- [teaser](#teaser)
16+
- [derivation](#derivation)
1617
- [colors](#colors)
1718
- integrations
1819
- [scalatest](#scalatest-integration)
@@ -37,7 +38,7 @@ The library is published for Scala 2.12 and 2.13.
3738
Add the following dependency:
3839

3940
```scala
40-
"com.softwaremill.diffx" %% "diffx-core" % "0.3.30"
41+
"com.softwaremill.diffx" %% "diffx-core" % "0.4.0"
4142
```
4243

4344
```scala
@@ -63,7 +64,7 @@ val left: Foo = Foo(
6364
// Some(Foo(Bar("asdf", 5), List(123, 1234), Some(Bar("asdf", 5))))
6465
// )
6566

66-
67+
import com.softwaremill.diffx.generic.auto._
6768
import com.softwaremill.diffx._
6869
compare(left, right)
6970
// res0: DiffResult = DiffResultObject(
@@ -87,6 +88,29 @@ Will result in:
8788
![example](https://github.com/softwaremill/diff-x/blob/master/example.png?raw=true)
8889

8990

91+
## Derivation
92+
93+
Diffx supports auto and semi-auto derivation.
94+
To use auto derivation add following import
95+
96+
`import com.softwaremill.diffx.generic.auto._`
97+
98+
or
99+
100+
extend trait
101+
102+
`com.softwaremill.diffx.generic.DiffDerivation`
103+
104+
105+
For semi-auto derivation you don't need any additional import, just define your instances using:
106+
```scala
107+
case class Product(name: String)
108+
case class Basket(products: List[Product])
109+
110+
val productDiff = Diff.derived[Product]
111+
val basketDiff = Diff.derived[Basket]
112+
```
113+
90114
## Colors
91115

92116
When running tests through sbt, default diffx's colors work well on both dark and light backgrounds.
@@ -104,7 +128,7 @@ If anyone has an idea how this could be improved, I am open for suggestions.
104128
To use with scalatest, add the following dependency:
105129

106130
```scala
107-
"com.softwaremill.diffx" %% "diffx-scalatest" % "0.3.30" % Test
131+
"com.softwaremill.diffx" %% "diffx-scalatest" % "0.4.0" % Test
108132
```
109133

110134
Then, extend the `com.softwaremill.diffx.scalatest.DiffMatcher` trait or `import com.softwaremill.diffx.scalatest.DiffMatcher._`.
@@ -124,7 +148,7 @@ Giving you nice error messages:
124148
To use with specs2, add the following dependency:
125149

126150
```scala
127-
"com.softwaremill.diffx" %% "diffx-specs2" % "0.3.30" % Test
151+
"com.softwaremill.diffx" %% "diffx-specs2" % "0.4.0" % Test
128152
```
129153

130154
Then, extend the `com.softwaremill.diffx.specs2.DiffMatcher` trait or `import com.softwaremill.diffx.specs2.DiffMatcher._`.
@@ -142,7 +166,7 @@ left must matchTo(right)
142166
To use with utest, add following dependency:
143167

144168
```scala
145-
"com.softwaremill.diffx" %% "diffx-utest" % "0.3.30" % Test
169+
"com.softwaremill.diffx" %% "diffx-utest" % "0.4.0" % Test
146170
```
147171

148172
Then, mixin `DiffxAssertions` trait or add `import com.softwaremill.diffx.utest.DiffxAssertions._` to your test code.
@@ -169,13 +193,11 @@ implicit val modifiedDiff: Diff[Person] = Derived[Diff[Person]].ignore[Person,St
169193

170194
## Customization
171195

172-
If you'd like to implement custom matching logic for the given type, create an implicit `Diff` instance for that
196+
If you'd like to implement custom matching logic for the given type, create an implicit `Diff` instance for that
173197
type, and make sure it's in scope when any `Diff` instances depending on that type are created.
174198

175-
If there is already a typeclass for a particular type, but you would like to use another one, you wil have to override existing instance. Because of the "exporting" mechanism the top level typeclass is `Derived[Diff]` rather then `Diff` and that's the typeclass you need to override.
176-
177-
To understand it better, consider following example with `NonEmptyList` from cats.
178-
`NonEmptyList` is implemented as case class so diffx will create a `Derived[Diff[NonEmptyList]]` typeclass instance using magnolia derivation.
199+
Consider following example with `NonEmptyList` from cats. `NonEmptyList` is implemented as case class so diffx
200+
will create a `Diff[NonEmptyList]` typeclass instance using magnolia derivation.
179201

180202
Obviously that's not what we usually want. In most of the cases we would like `NonEmptyList` to be compared as a list.
181203
Diffx already has an instance of a typeclass for a list. One more thing to do is to use that typeclass by converting `NonEmptyList` to list which can be done using `contramap` method.
@@ -184,18 +206,18 @@ The final code looks as follows:
184206

185207
```scala
186208
import cats.data.NonEmptyList
187-
implicit def nelDiff[T: Diff]: Derived[Diff[NonEmptyList[T]]] =
188-
Derived(Diff[List[T]].contramap[NonEmptyList[T]](_.toList))
209+
implicit def nelDiff[T: Diff]: Diff[NonEmptyList[T]] =
210+
Diff[List[T]].contramap[NonEmptyList[T]](_.toList)
189211
```
190212

191-
And here's an example customizing the `Diff` instance for a child class of a sealed trait
213+
And here's an example of customizing the `Diff` instance for a child class of a sealed trait
192214

193215
```scala
194216
sealed trait ABParent
195217
case class A(id: String, name: String) extends ABParent
196218
case class B(id: String, name: String) extends ABParent
197219

198-
implicit val diffA: Derived[Diff[A]] = Derived(Diff.gen[A].value.ignore[A, String](_.id))
220+
implicit val diffA: Diff[A] = Derived[Diff[A]].ignore[A, String](_.id)
199221
```
200222
```scala
201223
val a1: ABParent = A("1", "X")
@@ -204,9 +226,12 @@ val a2: ABParent = A("2", "X")
204226
// a2: ABParent = A("2", "X")
205227

206228
compare(a1, a2)
207-
// res5: DiffResult = Identical(A("1", "X"))
229+
// res6: DiffResult = Identical(A("1", "X"))
208230
```
209231

232+
As you can see instead of summoning bare instance of `Diff` for given `A` we summoned `Derived[Diff[A]]`.
233+
This is required in order to workaround self reference error.
234+
210235
You may need to add `-Wmacros:after` Scala compiler option to make sure to check for unused implicits
211236
after macro expansion.
212237
If you get warnings from Magnolia which looks like `magnolia: using fallback derivation for TYPE`,
@@ -217,17 +242,17 @@ with the compiler option `"-P:silencer:globalFilters=^magnolia: using fallback d
217242

218243
- [com.softwaremill.common.tagging](https://github.com/softwaremill/scala-common)
219244
```scala
220-
"com.softwaremill.diffx" %% "diffx-tagging" % "0.3.30"
245+
"com.softwaremill.diffx" %% "diffx-tagging" % "0.4.0"
221246
```
222247
`com.softwaremill.diffx.tagging.DiffTaggingSupport`
223248
- [eu.timepit.refined](https://github.com/fthomas/refined)
224249
```scala
225-
"com.softwaremill.diffx" %% "diffx-refined" % "0.3.30"
250+
"com.softwaremill.diffx" %% "diffx-refined" % "0.4.0"
226251
```
227252
`com.softwaremill.diffx.refined.RefinedSupport`
228253
- [org.typelevel.cats](https://github.com/typelevel/cats)
229254
```scala
230-
"com.softwaremill.diffx" %% "diffx-cats" % "0.3.30"
255+
"com.softwaremill.diffx" %% "diffx-cats" % "0.4.0"
231256
```
232257
`com.softwaremill.diffx.cats.DiffCatsInstances`
233258

version.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "0.3.31-SNAPSHOT"
1+
version in ThisBuild := "0.4.0"

0 commit comments

Comments
 (0)