These are chat archives for ramda/ramda

12th
Jul 2016
Bravi
@Bravilogy
Jul 12 2016 16:02
Guys, how can I run a specific function for each property in the object and return the result as an array?
Is there a way to do this?
Aldwin Vlasblom
@Avaq
Jul 12 2016 16:04
@Bravilogy You're probably looking to compose a map and a values together, in either order.
Bravi
@Bravilogy
Jul 12 2016 16:05
I have an array of objects:
[
   {name: 'John'},
   {name: 'Jane'}
]

// and I have the following:
const getTree = R.map(
   R.pipe(

   )
);
ah yes!
R.values that's what I needed
thank you
so I'd have two maps essentially. One for the whole array and one for each R.values
Aldwin Vlasblom
@Avaq
Jul 12 2016 16:10
@Bravilogy Yeah, something like:
const specificFunction = prop => prop + '!';
const mapValues = compose(map(specificFunction), values);
const program = map(mapValues);
program(arrayOfObjects)
Bravi
@Bravilogy
Jul 12 2016 16:20
basically I'm using mithril.js + ramda
const createTableRows = R.pipe(
    R.map(
        R.pipe(
            R.values,
            R.map(M('td'))
        )
    ),
    M('tr')
);

createTableRows(data);
this is awesome :D
Ebrahem Al-Hajeri
@ehajri
Jul 12 2016 20:46
I know this doesn't work because isRoot is not a function, but i hope it is obvious what i am trying to do:
var isRoot = R.not(R.has('parent', R.__));
R.filter(x => isRoot(x), objects);
oh hmm this gets me the result i want, but semantically, incorrect. how to retrain isRoot rather than !isRoot?
var isRoot = R.has('parent', R.__);
R.filter(x => !isRoot(x), objects);
R.complement, got it thanks :sparkles:
Brad Compton (he/him)
@Bradcomp
Jul 12 2016 20:57
@ehajri You can also use R.reject(isRoot, objects)
R.reject
Ebrahem Al-Hajeri
@ehajri
Jul 12 2016 20:58
@Bradcomp, when composing functions, when do I use R.__ and left it with less parameters for currying?
Brad Compton (he/him)
@Bradcomp
Jul 12 2016 21:00
You only need to R.__ if the parameter you are passing in is not the last one in the parameter list.
I misread your original. Sorry
R.complement is what you want
Ebrahem Al-Hajeri
@ehajri
Jul 12 2016 21:02
:thumbsup:
off-topic, do you recommend a good video that shows how good/beautiful functional programming? preferably in javascript. I fell in love with FP when I saw https://www.youtube.com/watch?v=m3svKOdZijA although he isn't the best speaker, but I really enjoyed the examples
Ebrahem Al-Hajeri
@ehajri
Jul 12 2016 21:27
I love ramda. I just had an adrenaline rush experimenting:
var sorted = R.sortBy(R.prop('index'));
var sorted = R.reverse(R.sortBy(R.prop('index')));       // error, sorted is not a function
var sorted = R.reverse(R.sortBy(R.prop('index'), R.__)); // error, sorted is not a function
var sorted = R.compose(R.reverse, R.sortBy(R.prop('index')));
Ebrahem Al-Hajeri
@ehajri
Jul 12 2016 21:48

This is so fun and great that i am feeling like a kid!
Started with

var getChilds = R.propEq('parent', order);
var childs = R.filter(x => getChilds(x), objects);

and ended up with

var isChildOf = R.propEq('parent');
var Children = R.compose(R.filter, isChildOf);
Children(order)(objects)
James Forbes
@JAForbes
Jul 12 2016 22:05
:) @ehajri
Ebrahem Al-Hajeri
@ehajri
Jul 12 2016 22:06
Hey @JAForbes! is there a functional way of doing:
return (
    children(sec.id)(_sections).length == 0 ?
        //lone
        m.component(lonemenu, {header: sec.header, route: sec.route || ''})
        :
        //got children!
        m.component(dropdownmenu, {header: sec.header, sub: children(sec.id)(_sections)})
);
James Forbes
@JAForbes
Jul 12 2016 22:15
Hmm tricky, maybe. It might be awkward because you want sec and children(sec.id)(_sections). Maybe have a look at @Avaq's combinator list, they might help. https://gist.github.com/Avaq/1f0636ec5c8d6aed2e45
Ebrahem Al-Hajeri
@ehajri
Jul 12 2016 22:28
I ended up doing (x=children(sec.id)(_sections)) => .. not sure though if it is syntactically correct, but thanks!
James Forbes
@JAForbes
Jul 12 2016 22:47
:)