These are chat archives for ramda/ramda

17th
May 2019
Lewis
@6ewis
May 17 08:58
hi
Rakesh Pai
@rakeshpai
May 17 11:33
Hi Lewis!
Galileo Sanchez
@galileopy
May 17 17:01
Hello
so long
I've been using this pattern a lot
const array  = [{ id: 1, value: 10 }, { id: 2, value: 10 }, { id: 3, value: 30 }, { id: 4, value: 40 }, { id: 5, value: 10 } ]
const newValue = { id: 5, value: 50 }
array.map((obj) =>  obj.id === newValue.id ?  newValue : obj )
now, eslint doesn't like arrow funcs with the ternary operator
Galileo Sanchez
@galileopy
May 17 17:06
and honestly expanding that expression in a full if block is kind of ugly and verbose
nevermind, I can use ifElse, forgot about that little one
1point7point4
@1point7point4
May 17 17:08
why represent your first constant like that instead of like {1: 10, 2: 10, 3: 30, 4: 40, 5: 10}
Galileo Sanchez
@galileopy
May 17 17:10
is just an example, those are values retrieved from a database, and usually I just perform some actions and send them back to be stored, having the id as a field rather than a key is useful
Rakesh Pai
@rakeshpai
May 17 17:11
Why does eslint complain about a ternary in an arrow function? That should be perfectly valid, isn't it? Is it just your eslint settings, maybe?
Galileo Sanchez
@galileopy
May 17 17:11
It is company policy, for some reason some people get confused with the ternary
when it is within an arrow
apparently when I break it into multiple lines it likes it
Rakesh Pai
@rakeshpai
May 17 17:13
Ah ok. I really like the ternary. I wish people didn't hate on it so much. <3 ternaries.
Galileo Sanchez
@galileopy
May 17 17:14
array.map(obj => obj.id === newValue.id
? newValue
: obj)
that works fine
Rakesh Pai
@rakeshpai
May 17 17:16
Ok... That's kinda strange. I'm not sure I'd say that one's more readable than the other. But well, if there's a eslint rules list, it's probably worth sticking to it.
Brad Compton (he/him)
@Bradcomp
May 17 17:37
map(when(propEq('id', newValue.id), always(newValue)), arr)
something like that would avoid the ternary
mitcho
@mitchoSR_twitter
May 17 21:30
does this qualify as a monad
const n = x => ({

    value: x,

    add(...args){
        return n(args.reduce((acc,cur) => acc + cur, this.value));
    },

    mul(...args){
        return n(args.reduce((acc,cur) => acc * cur, this.value));
    },

    div(...args){
        return n(args.reduce((acc,cur) => acc / cur, this.value));
    },

    sub(...args){
        return n(args.reduce((acc,cur) => acc - cur, this.value));
    },

    map(fn){
        return n(fn(this.value));
    },

    extract(){
        return this.value;
    }

});


let something = n(4).mul(4,4).extract();
console.log(something) //64
Brad Compton (he/him)
@Bradcomp
May 17 21:33
To be a monad, it will need to implement ap, of and chain in addition to map
mitcho
@mitchoSR_twitter
May 17 21:33
whats ap short for
Brad Compton (he/him)
@Bradcomp
May 17 21:36
apply I think. it takes a function wrapped in a monad, and a value, also wrapped, and applies the wrapped function to the wrapped value
mitcho
@mitchoSR_twitter
May 17 21:36
awesome ty
i didnt know monads had to implement certain methods
now i get it
makes sense
Lewis
@6ewis
May 17 21:38
I expected the opposite of R.head to be R.tail but nope
what's the opposite
Brad Compton (he/him)
@Bradcomp
May 17 21:39
R.last
Lewis
@6ewis
May 17 21:44
thank you
Brad Compton (he/him)
@Bradcomp
May 17 21:47
:bowtie:
Lewis
@6ewis
May 17 21:47
@Bradcomp how have you been
 const schedulesAssignments = await billingAPI.GETschedulesAssignments();
      const { groups } = await groupsAPI.GETallGroup();
      const schedules = await billingAPI.GETschedules();

      return schedulesAssignments.reduce((acc, assignment) => {
        const groupName = (groups.find((group) => assignment.groupId === group.groupId) || {}).name;
        const scheduleName = (
          schedules.find((schedule) => assignment.scheduleId == schedule.id) || {}
        ).scheduleName;

        if (!groupName || !scheduleName) return acc;

        acc.push({
          id: assignment.id,
          groupName,
          scheduleName,
        });

        return acc;
      }, []);
suggestions on improving this piece of code with Ramda welcome
Brad Compton (he/him)
@Bradcomp
May 17 21:49
Pretty good. Doing a lot less JS now, but still do quite a bit from time to time
Lewis
@6ewis
May 17 21:56
@Bradcomp what are you working with now?
Brad Compton (he/him)
@Bradcomp
May 17 22:01
I am now a platform engineer, so it depends on the day. Docker stuff, Java and CF, a little .NET, and still JS for quite a bit
Lewis
@6ewis
May 17 22:02
@Bradcomp what is a platform engineer? similar to devops? -- ah how do you like Java
Brad Compton (he/him)
@Bradcomp
May 17 22:03
It's pretty OK. We should sidebar this to PM though ;)
Lewis
@6ewis
May 17 22:05
[{a: 1}, { b: 2}] => into [{a: 1, foo: 1 coo: 1}, {b:2, foo: 2, coo: 2}] by going to api1 to look for id a:1 to get foo:2 and api2 to look for is a:1 to get coo1 ; that's . what the code above is . doing