These are chat archives for ramda/ramda

19th
Jan 2018
Gant Laborde
@GantMan
Jan 19 2018 00:03
I'm trying to find the minimum y coordinates in an array of points on a graph
some points can share the same X coordinate.
Anything jump out to you smart folk? bc Im' crunching this and it's a beast to me
Brad Compton (he/him)
@Bradcomp
Jan 19 2018 00:10
R.minBy
Gant Laborde
@GantMan
Jan 19 2018 00:11
Brad, I used minBy, but it only takes 2 items at a time, so I had to reduce. I also had to do some insane transforms. Here's my solution:
https://goo.gl/ZXfS4P
Am I happy it works? Yes... am I proud of what I did? more than I should be for this turd.
Brad Compton (he/him)
@Bradcomp
Jan 19 2018 00:20
groupBy is a really helpful function in these cases. This utilizes it to separate all the values by their date, and then maps over the object to get the minimum rating
Gant Laborde
@GantMan
Jan 19 2018 00:22
Beautiful code, thanks so much Brad!
I feel like I just leveled up
Brad Compton (he/him)
@Bradcomp
Jan 19 2018 00:23
I don't mean to disparage your solution by the way. I like yours too, just providing an alternative
Dennie de Lange
@tkvw
Jan 19 2018 10:01
Is there some cool stepping debugger function for Ramda? Currently I wrote a simple utility function for it:
const sayWhat = message => next => function(){
  const outcome = apply(next,arguments)
  console.log(message,outcome);
  return outcome;
}
Denis Stoyanov
@xgrommx
Jan 19 2018 12:53
@tkvw tap(console.log)
Dennie de Lange
@tkvw
Jan 19 2018 13:05
@xgrommx : nice! does this exists for arguments as well? I quessed proxy, but is doesn't exists
James Gardner
@james-gardner
Jan 19 2018 13:46

I need to mitigate the following from returning 'undefined':

const getRole = (roles) => find(
        where({ roles: hasSubset(roles) })
);

as my pipeline will fail because the next call expects .. something. Is this a good use case for 'Maybe' ?

Rolf Strijdhorst
@rolfst
Jan 19 2018 13:55
yes or a defaultTo
Dennie de Lange
@tkvw
Jan 19 2018 15:05
Just curious, is this a good way to ensure the argument is taken as an array?
ifElse(pipe(nthArg(0),type,equals("Array")),nthArg(0),unapply(identity))
Brad Compton (he/him)
@Bradcomp
Jan 19 2018 15:49
@james-gardner What do you want to happen if no item is found?
@tkvw How many arguments are there? what's the shape of your data?
Dennie de Lange
@tkvw
Jan 19 2018 15:51
either an array of values, or the values as arguments. So sum(1,2,3) should work and sum([1,2,3])
Brad Compton (he/him)
@Bradcomp
Jan 19 2018 15:55
That looks like it will work then...
compose(flatten, Array.from)(arguments)
If it can be assumed that none of the array items are arrays themselves then that will work too
I guess it would also require a wrapping function
yours is probably better :)
Dennie de Lange
@tkvw
Jan 19 2018 16:06
Thanks, I think this is better ifElse(Array.isArray,identity,unapply(identity))
Brad Compton (he/him)
@Bradcomp
Jan 19 2018 16:09
:+1: