All Projects → bizzabo → diff

bizzabo / diff

Licence: other
Visually compare Scala data structures with out of the box support for arbitrary case classes.

Programming Languages

scala
5932 projects

Projects that are alternatives of or similar to diff

play-json-extensions
+22 field case class formatter and more for play-json
Stars: ✭ 193 (+7.82%)
Mutual labels:  backend, rnd, xdotai
typeless
running wild with shapeless
Stars: ✭ 16 (-91.06%)
Mutual labels:  backend, rnd, xdotai
awesome-coder-resources
编程路上加油站!------【持续更新中...欢迎star,欢迎常回来看看......】【内容:编程/学习/阅读资源,开源项目,面试题,网站,书,博客,教程等等】
Stars: ✭ 54 (-69.83%)
Mutual labels:  backend
dashd-rpc
Dash Client Library to connect to Dash Core (dashd) via RPC
Stars: ✭ 17 (-90.5%)
Mutual labels:  backend
be-the-hero-omnistack-11
Semana OmniStack 11 - Be The Hero [possui alterações pessoais]
Stars: ✭ 14 (-92.18%)
Mutual labels:  backend
gae-vue-webapp2-starter
A simple GAE Vue Webapp2 starter project.
Stars: ✭ 17 (-90.5%)
Mutual labels:  backend
kasir
Cashier Management & Inventory Management System
Stars: ✭ 28 (-84.36%)
Mutual labels:  backend
kotlin-no-backend
Lista de empresas que utilizam Kotlin no Brasil.
Stars: ✭ 46 (-74.3%)
Mutual labels:  backend
hesperides
Configuration management tool providing universal text file templating and properties editing through a REST API or a webapp (backend part)
Stars: ✭ 35 (-80.45%)
Mutual labels:  backend
Dragon
基于 .Net Core 的后端基础框架
Stars: ✭ 17 (-90.5%)
Mutual labels:  backend
FSharp-CrossPlatform
This is a sample F# project that uses the SAFE stack for web frontend/backend and Fabulous/Xamarin for the iOS and Android mobile apps
Stars: ✭ 23 (-87.15%)
Mutual labels:  backend
backend-server
📠 The backend of the Fairfield Programming Association website.
Stars: ✭ 26 (-85.47%)
Mutual labels:  backend
trampolim
A modern Python build backend
Stars: ✭ 39 (-78.21%)
Mutual labels:  backend
backend
Ergonode backend repository
Stars: ✭ 100 (-44.13%)
Mutual labels:  backend
Everything-Tech
A collection of online resources to help you on your Tech journey.
Stars: ✭ 396 (+121.23%)
Mutual labels:  backend
todo
An example todo application with Go!
Stars: ✭ 61 (-65.92%)
Mutual labels:  backend
Pharmacy-Mangment-System
👨‍💻 🏥 MEAN stack Pharmacy Management system.
Stars: ✭ 229 (+27.93%)
Mutual labels:  backend
typed-ajv
Define TypeScript types and JSON Schema schemas from the same declarations
Stars: ✭ 18 (-89.94%)
Mutual labels:  backend
browser-push
Complete workout and guidelines to add web push notifications support for your webapp without third-party notification provider
Stars: ✭ 67 (-62.57%)
Mutual labels:  backend
vagas
Espaço para a divulgação de vagas para desenvolvedores backend via issues do Github.
Stars: ✭ 5,685 (+3075.98%)
Mutual labels:  backend

diff

Join the chat at https://gitter.im/xdotai/diff

A tool to visually compare Scala data structures with out of the box support for arbitrary case classes.

Be aware: Collections (List, Seq, etc.) are compared like sets, i.e. ignoring order.

SBT Dependencies

Scala 2.11/2.12

"ai.x" %% "diff" % "2.0.1"

Scala 2.10

Stopped working in 1.2.0 due to what seems like a Scala compiler bug. See #18

Usage

import ai.x.diff.DiffShow
import ai.x.diff.conversions._
println(  DiffShow.diff[Foo]( before, after ).string  )

Be aware that diff throws an Exception if a DiffShow type class instance for some field can't be found rather than a type error. If you use diff in a testing or debugging scenario that's usually not a problem. The advantage is that the Exception can tell exactly which instance wasn't found. A type error can only point to the outer most class (Foo in this case) even if it is actually one of it's deeply nested fields that is lacking an instance for it's type. Knowing only Foo would not be very helpful to pin point which instance is missing.

Output

example-output

Code

sealed trait Parent
case class Bar( s: String, i: Int ) extends Parent
case class Foo( bar: Bar, b: List[Int], parent: Option[Parent] ) extends Parent

val before: Foo = Foo(
  Bar( "asdf", 5 ),
  List( 123, 1234 ),
  Some( Bar( "asdf", 5 ) )
)
val after: Foo = Foo(
  Bar( "asdf", 66 ),
  List( 1234 ),
  Some( Bar( "qwer", 5 ) )
)

Helpful tips

import ai.x.diff._

Custom comparison

Sometimes you may need to write your own type class instances. For example for non-case classes that don't compare well using ==.

import ai.x.diff._
import org.joda.time.LocalTime

implicit def localTimeDiffShow: DiffShow[LocalTime] = new DiffShow[LocalTime] {
  def show ( d: LocalTime ) = "LocalTime(" + d.toString + ")"
  def diff( l: LocalTime, r: LocalTime ) =
    if ( l isEqual r ) Identical( l ) else Different( l, r )
}

Ignore parts of data

Sometimes you may want to ignore some parts of your data during comparison. You can do so by type, e.g. for non-deterministic parts like ObjectId, which always differ.

def ignore[T]: DiffShow[T] = new DiffShow[T] {
  def show( t: T ) = t.toString
  def diff( left: T, right: T ) = Identical( "<not compared>" )
  override def diffable( left: T, right: T ) = true
}
implicit def LocationIdShow: DiffShow[LocationId] = ignore[LocationId]

Influence comparison in collections

When comparing collections you can influence if two elements should be compared or treated as completely different. Comparing elements shows their partial differences. Not comparing them shows them as added or removed.

implicit def PersonDiffShow[L <: HList](
  implicit
  labelled:  LabelledGeneric.Aux[Person, L],
  hlistShow: Lazy[DiffShowFields[L]]
): DiffShow[Person] = new CaseClassDiffShow[Person, L] {
  override def diffable( left: Person, right: Person ) = left._id === right._id
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].