SkillAgentSearch skills...

Pabloware.diff

Readable diff & patch lib. Best used with maps.

Install / Use

/learn @PawelStroinski/Pabloware.diff
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

pabloware.diff

Readable diff & patch lib. Best used with maps.

Clojars Project

Rationale

While there are many diff & patch libs around, I could not find one which shows the shape of a diffed data in the diff itself, i.e. I wanted a diff of a map to be a map. Also, it should be able to use that diff to do patching.

This lib does exactly that but is very basic in terms of diffing lists and vectors. There are alternative libs for that.

Usage

=> (require '[pabloware.diff :as p])

=> (def band
     {:id     1
      :name   "Esbjörn Svensson Trio"
      :active {:from 1993}
      :genres #{:jazz :instrumental-music}
      :albums [{:title "When Everyone Has Gone", :year  1993}
               {:title "EST Plays Monk"          :year  1996}]})

=> (-> band
       (dissoc :id)
       (assoc-in [:active :to] 2008)
       (update :genres conj :bepop)
       (update :albums conj {:title "Winter in Venice", :year 1997}))

=> (p/diff band *1)
{:id     ::p/-
 :active {:to 2008}
 :genres #{:bepop}
 :albums [::p/+ {:title "Winter in Venice", :year 1997}]}

=> (= *2 (p/patch band *1))
true

The test namespace contains edge cases as well as a generative test using spec.

Bullet points

Goals:

  • Straightforward implementation
  • Easy to read by humans diffs, especially for maps

Nice-to-haves:

  • Small diff size

Non-goals:

  • Speed

License

Copyright © 2019 Paweł Stroiński

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

View on GitHub
GitHub Stars9
CategoryDevelopment
Updated5y ago
Forks0

Languages

Clojure

Security Score

75/100

Audited on Nov 2, 2020

No findings