These are chat archives for ramda/ramda

14th
Jul 2016
Baqer Mamouri
@bmamouri
Jul 14 2016 02:35

Hey everyone. Is it possible to reduce an object with Ramda?

This is what I am trying to do:

R.reduce(R.add, x => x.fullname === '' ? 1 : 0)({0: {fullname: ''}, 1: {fullname: 'bob'}})

I want to count the number of objects that don’t have fullname.

Brad Compton (he/him)
@Bradcomp
Jul 14 2016 02:40
@bmamouri I don't think you can reduce an object, but can you use R.values to convert it to a list?
@ram-bot
compose(length, keys, filter(compose(isEmpty, prop('fullname')))({0: {fullname: ''}, 1: {fullname: 'bob'}})
ram-bot
@ram-bot
Jul 14 2016 02:44
missing ) after argument list
Baqer Mamouri
@bmamouri
Jul 14 2016 02:45
Something like this:
R.pipe(
  R.toPairs,
  R.reduce( (acc, item) => acc + (item[1].fullname == '' ? 1 : 0), 0)
)({0: {fullname: ''}, 1: {fullname: 'bob'})
But is there a better way to do this
Brad Compton (he/him)
@Bradcomp
Jul 14 2016 02:45
You can filter the object and take the length of the keys
@ram-bot
compose(length, keys, filter(compose(isEmpty, prop('fullname'))))({0: {fullname: ''}, 1: {fullname: 'bob'}})
ram-bot
@ram-bot
Jul 14 2016 02:46
1
Baqer Mamouri
@bmamouri
Jul 14 2016 02:46
@Bradcomp the problem with that approach is that filter need to create another list with is memory intesive. The same problem exists with toPairs. I am looking for a reducer that works on the object directly, because my list is very big.
Brad Compton (he/him)
@Bradcomp
Jul 14 2016 02:50
Ah, I see. What about using keys then and just accessing the object directly? http://goo.gl/YZrGfu
not as pretty I'll admit, but it doesn't need to reproduce the object
Baqer Mamouri
@bmamouri
Jul 14 2016 02:53
That is actually pretty good @Bradcomp. it uses clousre, but I don’t think that is really a performance problem. Maybe in rambda we need an reduceObj function. Kind of like mapObjIndexed
Brad Compton (he/him)
@Bradcomp
Jul 14 2016 02:55
It would be nice, but there are issues with the fact that objects are in a sense unordered. See ramda/ramda#1067 for a discussion of the matter.
Baqer Mamouri
@bmamouri
Jul 14 2016 03:18
Thanks heaps for the link @Bradcomp.
Brad Compton (he/him)
@Bradcomp
Jul 14 2016 03:19
:+1:
Tushar Mathur
@tusharmath
Jul 14 2016 09:14
what would be the closest library to ramda for python ?
Tushar Mathur
@tusharmath
Jul 14 2016 09:30
@xgrommx :+1:
not a lot of options
redwyn
@redwyn
Jul 14 2016 13:32
Hello. Is it intended for R.set(lens, val, obj) to insert the property with the given value, if it is not found? I thought I'd need the partial.lens library for that
And can it be expected for this behavior not to change...
clintonjohn
@clintonjohn
Jul 14 2016 17:50
With this R.partial "greeting" example, where in the code are the arguments linked with their parameters? I can infer it, but don't see how the computer is instructed to do it.
clintonjohn
@clintonjohn
Jul 14 2016 17:57
In line 8, how is the argument 'hello' associated with the arg greet parameter (salutation)?
Brad Compton (he/him)
@Bradcomp
Jul 14 2016 18:00
@clintonjohn under the hood it's aggregating the arguments in order, then using apply with the final function once it has everything it needs.