Skip to content

Instantly share code, notes, and snippets.

@pashields
Last active January 3, 2016 02:09
Show Gist options
  • Save pashields/8393867 to your computer and use it in GitHub Desktop.
Save pashields/8393867 to your computer and use it in GitHub Desktop.
A little json-y diff action in clojure.
(ns line-compare.core
(:require [cheshire.core :refer :all]
[clojure.set :refer :all]
[clojure.java.io :refer :all]))
(defn read-file
[file]
(with-open [rdr (reader file)]
(set (parsed-seq rdr))))
(defn diff-strings
[filename lines]
(map #(str "Only in " filename ": " %) lines))
(defn -main
[orig-file copy-file]
(let [orig (read-file orig-file)
copy (read-file copy-file)
orig-only (difference orig copy)
copy-only (difference copy orig)
diffs (concat
(diff-strings orig-file orig-only)
(diff-strings copy-file copy-only))]
(doseq [line diffs] (println line))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment