These are chat archives for ramda/ramda

26th
Jul 2016
hemanth.hm
@hemanth
Jul 26 2016 07:14
What's wrong? with R.omit(R.isNil, arrayOfObjects)
hemanth.hm
@hemanth
Jul 26 2016 07:20
I am removing null from an array of objects
R.filter(R.isNil, arrayOfObjects) also not helping
Aldwin Vlasblom
@Avaq
Jul 26 2016 07:53
@hemanth You're looking for
R.reject
Aldwin Vlasblom
@Avaq
Jul 26 2016 07:54
omit takes an array of keys to omit, rather than an actual predicate, filter keeps all the things for which your predicate returns true, and reject drops all the things for which your predicate returns true.
Alternatively, you can complement isNil: filter(complement(isNil), arrayOfObjects)
hemanth.hm
@hemanth
Jul 26 2016 07:55
complement makes sense
Aldwin Vlasblom
@Avaq
Jul 26 2016 07:56
Right. So you're not trying to "remove nulls from an array of objects". You're trying to remove null values from objects?
hemanth.hm
@hemanth
Jul 26 2016 07:57
R.filter(R.complement(R.isNil),shipping) didn't help, array of object, removing null from object, filter should iterate over them right?
Aldwin Vlasblom
@Avaq
Jul 26 2016 07:58
You need to map over the array, and then filter over every value: http://goo.gl/NbMtsY
So map(filter(..))
Or reject, in your case, which is just the complement of filter.
hemanth.hm
@hemanth
Jul 26 2016 08:01
I was trying R.not as well
[].filter((v,i,a) => a[v] !==null) would produce the same result right?
Aldwin Vlasblom
@Avaq
Jul 26 2016 08:02
That produces the same result as R.reject(R.isNil, []).
You are filtering the array, whilst you want to filter the values of objects inside the array.
R.map(R.reject(R.isNil), shipping) (as shown in the link) is working for me.
hemanth.hm
@hemanth
Jul 26 2016 08:04
@Avaq Makes sense, agree, thanks.
Aldwin Vlasblom
@Avaq
Jul 26 2016 08:04
You can view it like this:
const rejectNils = R.reject(R.isNil);
const rejectAllNils = R.map(rejectNils);

rejectAllNils(arrayOfObjects)
So rejectNils operates on a single object, dropping its nil values, and wrapping it in map to produce rejectAllNils will make it iterate over an array of objects.
hemanth.hm
@hemanth
Jul 26 2016 08:09
Got it, nice, I miss read reject as map and reject
@Avaq Do you think, this is good use case for lenses? https://github.com/hemanth/config-hyperterm/blob/master/index.js#L24
Aldwin Vlasblom
@Avaq
Jul 26 2016 08:11
Yeah, I think it's a little confusing, because reject (or filter) can work on both arrays and objects. Maybe this clears it up:
@ram-bot R.reject(R.isNil, [{a: null}, null, null, null, {b: null}])
ram-bot
@ram-bot
Jul 26 2016 08:11
[ { a: null }, { b: null } ]
Aldwin Vlasblom
@Avaq
Jul 26 2016 08:11
See how it filters the array and not the objects inside it?
hemanth.hm
@hemanth
Jul 26 2016 08:11
yup, got it 👼
@Avaq please have a look at the lenses usage when free.
Aldwin Vlasblom
@Avaq
Jul 26 2016 08:25
I don't work enough with lenses in order to judge which is good usage and which is not. I think they can be used for a wide range of things, and I believe a whole style of programming evolved around them. Though I think you're merely using them for property access. I would have gone for prop in your use-case, I think: const getter = R.prop(shortHandMap[prop] || camelCase(prop))
hemanth.hm
@hemanth
Jul 26 2016 08:27

Though I think you're merely using them for property access.

It includes more than that.

hemanth.hm
@hemanth
Jul 26 2016 10:48
const notNil = R.not(R.isNil) // is not right
hemanth @hemanth paws at @raine (looong time, hope he remembers me 😇)
zeecher Game
@zeecher
Jul 26 2016 11:12
Hi all, how to break out of forEach loop
hemanth.hm
@hemanth
Jul 26 2016 11:21
@zeecher Why do you want to breakout?
you probably need some or any
Aldwin Vlasblom
@Avaq
Jul 26 2016 11:22
@zeecher You can abuse some, by returning true to break, and false otherwise. It's just that though, abuse. It likely means you would have wanted to filter or take or whatever from your array beforehand to get rid of values you don't need.
hemanth.hm
@hemanth
Jul 26 2016 11:23
@Avaq Agree, filter or take is a better option
Aldwin Vlasblom
@Avaq
Jul 26 2016 11:24
Ideally, you never use forEach, but always map, filter, reduce, etc. Because forEach doesn't return anything. You're running it purely for its side-effects.
hemanth.hm
@hemanth
Jul 26 2016 11:27
In case you want a quick brush yup on side-effects http://git.io/fp-jargons#side-effects
Aldwin Vlasblom
@Avaq
Jul 26 2016 11:28
@hemanth
const notNil = R.complement(R.isNil)
const TRUE = R.not(false)
Denis Stoyanov
@xgrommx
Jul 26 2016 11:28
R.T, R.F
Aldwin Vlasblom
@Avaq
Jul 26 2016 11:29
Yeah, I'm just illustrating the difference between R.not and R.complement @xgrommx :)
zeecher Game
@zeecher
Jul 26 2016 11:29
@Avaq @hemanth I have two different list of objects
list A : [{a: 2 , b:3, c: 4}, {a: 1 , b:4, c: 5}]

list B : [{a: 2 , b:3}, {a: 1 , b:4}]

I want to merge objects inside A and B to New List C, if they have same value of 'a' and 'b' properties, something like:

    R.map(b => {

        R.find(R.propEq('a', R.prop('a', b)) && R.propEq('b', R.prop('b', b)))(A);

    } , B);
hemanth.hm
@hemanth
Jul 26 2016 11:29
@Avaq heh heh, figured it, nice!
Denis Stoyanov
@xgrommx
Jul 26 2016 11:31
@Avaq oh) sure) probably if we have k-combinator and c-combinator we can use it like
k(true)(false) => true
c(k) (true)(false) => false
hemanth.hm
@hemanth
Jul 26 2016 11:32
@zeecher differenceWith must help you here
zeecher Game
@zeecher
Jul 26 2016 11:37
@hemanth I need output in new list in this format => list C [{a: 2 , b:3, c: 4}, {a: 1 , b:4, c: 5}] only if property of B.a == A.a and B.b ===A.b then merge for example A[0] & B[0] and put to list C[0]
zeecher Game
@zeecher
Jul 26 2016 11:47
I am using this way: (but on large list it takes around 7-8 seconds to execute which is pretty slow)
 var listC =  R.map(b => {
    var x = R.find(R.propEq('a', R.prop('a', b)) && R.propEq('b', R.prop('b', b)))(A);
    if(x) {
       return R.merge(b, x);
    }
    return b;
 }, B);
zeecher Game
@zeecher
Jul 26 2016 11:53
Does anybody know how to achieve this with faster code ?
hemanth.hm
@hemanth
Jul 26 2016 13:51
No slack channel, yet?
Keith Alexander
@kwijibo
Jul 26 2016 14:01
What would be a good folktale/ramda-fantasy style ADT for representing a modal dialogue?
Barney Carroll
@barneycarroll
Jul 26 2016 14:03
@kwijibo XML? :hides: