-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathdiff.objects.json
More file actions
1 lines (1 loc) · 1.14 KB
/
diff.objects.json
File metadata and controls
1 lines (1 loc) · 1.14 KB
1
{"title":"diffing objects","name":"Diff Objects","description":"similar to <a href=\"http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Maps.html#difference%28java.util.Map,%20java.util.Map%29\">Guava's Maps Difference</a>","source":"let R = require('ramda');\n\nvar groupObjBy = R.curry(R.pipe(\n // Call groupBy with the object as pairs, passing only the value to the key function\n R.useWith(R.groupBy, [R.useWith(__, [R.last]), R.toPairs]),\n R.map(R.fromPairs)\n))\n\nvar diffObjs = R.pipe(\n R.useWith(R.mergeWith(R.merge), [R.map(R.objOf(\"leftValue\")), R.map(R.objOf(\"rightValue\"))]),\n R.groupObjBy(R.cond([\n [\n R.both(R.has(\"leftValue\"), R.has(\"rightValue\")),\n R.pipe(R.values, R.ifElse(R.apply(equals), R.always(\"common\"), R.always(\"difference\")))\n ],\n [R.has(\"leftValue\"), R.always(\"onlyOnLeft\")],\n [R.has(\"rightValue\"), R.always(\"onlyOnRight\")],\n ])),\n R.evolve({\n common: R.map(R.prop(\"leftValue\")),\n onlyOnLeft: R.map(R.prop(\"leftValue\")),\n onlyOnRight: R.map(R.prop(\"rightValue\"))\n })\n);\n\ndiffObjs({a: 1, c: 5, d: 4 }, {a: 1, b: 2, d: 7});\n"}