GithubHelp home page GithubHelp logo

bplommer / diffx Goto Github PK

View Code? Open in Web Editor NEW

This project forked from softwaremill/diffx

0.0 1.0 0.0 670 KB

Pretty diffs for scala case classes

License: Apache License 2.0

Scala 99.26% Shell 0.74%

diffx's Introduction

diffx

Build Status Maven Central Gitter

Pretty diffs for case classes.

The library is published for Scala 2.12 and 2.13.

Scalatest integration

To use with scalatest, add the following dependency:

"com.softwaremill.diffx" %% "diffx-scalatest" % "0.2.0"

Then, extend the com.softwaremill.diffx.scalatest.DiffMatcher trait or import com.softwaremill.diffx.scalatest.DiffMatcher._. After that you will be able to use syntax such as:

left should matchTo(right)

Giving you nice error messages:

example

Using directly

Add the following dependency:

"com.softwaremill.diffx" %% "diffx-core" % "0.2.0"

Then call:

import com.softwaremill.diffx.Diff

//import this or extend the trait with the same name
import com.softwaremill.diffx.DiffInstances._

Diff[T].diff(o1, o2)

Customization

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

Ignoring

Fields can be excluded from comparision by calling the ignore method on the Diff instance. Since Diff instances are immutable, the ignore method creates a copy of the instance with modified logic. You can use this instance explicitly. If you still would like to use it implicitly, you first need to summon the instance of the Diff typeclass using the Derived typeclass wrapper: Derived[Diff[Person]]. Thanks to that trick, later you will be able to put your modified instance of the Diff typeclass into the implicit scope. The whole process looks as follows:

implicit modifiedDiff: Diff[Person] = Derived[Diff[Person]].ignore(_.name)

Tagging support

Support for tagged types can be added easily by providing an additional generic instance of the Diff type class

implicit def taggedDiff[T:Diff, U]: Diff[T @@ U] = Diff[T].contramap(identity)

diffx's People

Contributors

adamw avatar ghostbuster91 avatar kubukoz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.