These are chat archives for ramda/ramda

2nd
Sep 2015
hemanth.hm
@hemanth
Sep 02 2015 06:34
Nice, so it's like R.keys(R.prop(['name'],data)).sort()
Can keys + sort be composed into one single function?
Scott Christopher
@scott-christopher
Sep 02 2015 06:50
@hemanth Try R.compose(R.sortBy(R.identity), R.keys)
hemanth.hm
@hemanth
Sep 02 2015 06:52
@scott-christopher Nice, but it's not doing a natural sort.
Scott Christopher
@scott-christopher
Sep 02 2015 06:58
If you want specific sorting behaviour you can use R.sort and provide your own comparator function instead.
hemanth.hm
@hemanth
Sep 02 2015 07:22
hmm, was thinking of the same, cool, will stick with R.prop for now.
Alex Afonin
@Tuch
Sep 02 2015 18:03
Guys, maybe someone use ramba a with flux? Need examples :)
Examples of big app.. With many entities..
Sergey Rubanov
@chicoxyzzy
Sep 02 2015 18:16
@Tuch there are not so much examples of big apps open sourced. btw I use Ramda with Alt (but I plan to migrate to lodash-fp in future)
Alex Afonin
@Tuch
Sep 02 2015 18:19
Hm. Ok, thanks you, will try too
Jason Heard
@101100
Sep 02 2015 18:36

I'm trying to do something without writing the keyword function (i.e. creating the function using R.* as an exercise). The goal is a function that takes two arguments, the first is a list of ids, the second is a list of objects (with an id property). The function should return the items from the second list that have ids from the first list. Here is a small working example (with one use of function):

var a = [ 1, 2, 3 ];
var b = [ {id: 1, b: 'Yay!' }, { id: 3, b: 'Oh yeah!' }, { id: 4, b: 'Oh noes!' } ];

var answerFunc = function (x, y) { R.pipe(R.map(R.pipe(R.unary(R.propEq('id')), R.partialRight(R.find, y))), R.filter(R.identity))(x) };

answerFunc(a, b);
// -> [ { id: 1, b: 'Yay!' }, { id: 3, b: 'Oh yeah!' } ]

I can't figure out how to "extract" the y parameter from the middle so I can say something like:

var answerFunc = R....

Any ideas?

Aldwin Vlasblom
@Avaq
Sep 02 2015 19:11
@101100 R.useWith(R.filter, R.useWith(R.pipe, R.always(R.prop('id')), R.flip(R.contains))(null), R.identity)
A little bit hacky, I couldn't find an easy way to push a into R.flip(R.contains) without affecting the composition with R.prop('id'). So now I'm calling R.always(R.prop('id')) with null.
But it works. :P
Aldwin Vlasblom
@Avaq
Sep 02 2015 19:16
"Extracting the parameter from the middle" like you said is done with R.useWith or R.converge (if I understand you correctly).

Basically:
converge(f, a, b)(x, y) === f(a(x, y), b(x, y))
useWith(f, a, b)(x, y) === f(a(x), b(y))

So the passed in variable makes its way "deeper" into "the middle".

Jason Heard
@101100
Sep 02 2015 19:55
@Avaq Thanks for the solution and explanation!
Jason Heard
@101100
Sep 02 2015 20:36
I managed to remove the (null) hack: R.useWith(R.filter, R.pipe(R.unary(R.flip(R.contains)), R.partial(R.pipe, R.prop('id'))), R.identity), but I'm not sure if it is "better".
Aldwin Vlasblom
@Avaq
Sep 02 2015 20:50
Certainly interesting, using partial to prepare a pipeline for its final function, I would never have thought of that. It's still a little convoluted, but I would say it's an improvement as there's no more artificial noop in there (always(x)(null) to get x :P ).