These are chat archives for ramda/ramda

2nd
Sep 2017
Rendall
@rendall
Sep 02 2017 15:52
Is there a function that will return the diff of two objects? That is to say: diffObj({a:1, b:2, c:3}, {a:1, b:5, c:3}) // => {b: 5}
Because if so, I built one and wasted the time :)
If not, I'm happy to make a pull request.
Philipp Wille
@Yord
Sep 02 2017 15:56
@rendall I think there is not, apart from the Ramda cookbook entry: https://github.com/ramda/ramda/wiki/Cookbook#diffobjs---diffing-objects-similar-to-guavas-mapsdifference
Rendall
@rendall
Sep 02 2017 15:58
Hmm. Mine's just a recurse.
var diffObj = function (origObj, newObj, compObj, keysToCompare) {
    if (compObj == undefined)
        return diffObj(origObj, newObj, R.clone(newObj));
    if (keysToCompare == undefined)
        return diffObj(origObj, newObj, compObj, R.keys(origObj));
    if (keysToCompare.length == 0)
        return compObj;
    var prop = R.head(keysToCompare);
    var remKeys = R.tail(keysToCompare);
    return R.eqProps(prop, origObj, newObj) ? diffObj(origObj, newObj, R.dissoc(prop, compObj), remKeys) : diffObj(origObj, newObj, compObj, remKeys);
};
Okay, I'll make a PR and see what happens.
Thanks @Yord
Lihai Ben-Haim
@lihaibh
Sep 02 2017 20:33
how can i check the condition "is not an array"
i wrote this code
R.filter(R.both(R.is(Object), R.compose(R.not, R.isArrayLike)), arr).length
but it doesnt work
i get an error that pipe expects for 1 argument atleast
it should work
i provide an array
than for each object in the array i check if its type of Object and not type of Array
Brad Compton (he/him)
@Bradcomp
Sep 02 2017 21:04
@lihaibh Like this?
@ram-bot
filter(both(is(Object), complement(is(Array))))([{},{},{},[],[],1,2,3])
ram-bot
@ram-bot
Sep 02 2017 21:04
[ {}, {}, {} ]
Lihai Ben-Haim
@lihaibh
Sep 02 2017 21:05
yup
cool feature this rambot i didnt know
Brad Compton (he/him)
@Bradcomp
Sep 02 2017 21:05
compose(not, is(Array)) should work fine too
Lihai Ben-Haim
@lihaibh
Sep 02 2017 21:05
i tried isArrayLike function
your solution works fine
thank you
Brad Compton (he/him)
@Bradcomp
Sep 02 2017 21:07
I feel like that should work too. I don't really trust that function
:+1:
Looks like isArrayLike was removed
Lihai Ben-Haim
@lihaibh
Sep 02 2017 21:13
ye i see
but the problem is that in defenately typed library
the typescript version of ramda
this function appears so the auto completion works
but the runtime fails