These are chat archives for ramda/ramda

12th
Apr 2015
lluft
@lluft
Apr 12 2015 09:49
var people = [{name: "timo",index: 0}];  
var emails = ["timo@example.com"];

var fetchEmail = function(person){
    return Q.resolve({email:emails[person.index]});
};

var attachEmailToPerson = function(person) {
    return R.pipeP(
        fetchEmail,
        R.merge(person)
    )(person);
};

var attachEmailToPersons = R.map(attachEmailToPerson);

Q.all(attachEmailToPersons(people))
.then(function(people) {console.log(people);});
HI, I have parent data sets that I need to fetch and which should then get decorated with another data set that needs to be fetched asynchronously as well. The first one provides the keys to fetch the second one. Is there a way to write the attachEmailToPerson function without having to wrap R.pipeP like I did?
Michael Hurley
@buzzdecafe
Apr 12 2015 15:53
hey gents, i got the four basic forms of microKanren implemented and at least basically tested. Please check it out when you get a chance:
https://github.com/buzzdecafe/rlg
David Chambers
@davidchambers
Apr 12 2015 18:16
@lluft, since you want to feed in person to both functions you should consider R.converge.
@buzzdecafe, I’ll need to learn about microKanren before I can provide any feedback. ;)
Hardy Jones
@joneshf
Apr 12 2015 18:25
@buzzdecafe nice!
One of my friends works with Jason Hemann. He apparently loves seeing these things. Do you mind if I tell her to tell him about it?
Scott Sauyet
@CrossEye
Apr 12 2015 18:59

@lluft: without setting up more infrastructure than I'm up to at the moment, I'm not certain about this, but it looks as though David's suggestion of R.converge would work well in combination with R.pipeP:

var attachEmailToPerson = R.converge(R.pipeP, fetchEmail, R.merge)

This feels odd since converge is usually used in place of a compose/pipe, but it at least looks like it would work.

Michael Hurley
@buzzdecafe
Apr 12 2015 19:07
@joneshf please do! thanks
Scott Sauyet
@CrossEye
Apr 12 2015 19:11
@buzzdecafe: I think I'm finally starting to understand. One question: Is walk meant to be public, or is it an implementation detail?
Michael Hurley
@buzzdecafe
Apr 12 2015 19:12
the public API is in index.js
just the four forms
Scott Sauyet
@CrossEye
Apr 12 2015 19:12
ok, only looked at the tests so far.
Michael Hurley
@buzzdecafe
Apr 12 2015 19:12
i also gotta implement succeed/fail as streams instead of arrays
lluft
@lluft
Apr 12 2015 22:07
@CrossEye @davidchambers thanks for the reply. I tried your code snippet. I got an error since fetchEmail returns a value and not a function. Fiddled arround with R.call but couldn’t put it to work in anyway. I worked around by wrapping it in another function, then the probelm is that calling attachEmailToPerson(person) returns a function instead of the result, I fixed it in the fiddle by sending in function(a,b){return R.pipeP(a,b)() } as the first arguement to R.converge. Seems to complicate it quite a lot without any gain. Here is the link to the fiddle: http://jsfiddle.net/p4mucjae/
Scott Sauyet
@CrossEye
Apr 12 2015 23:21
Yes, sorry, @lluft, I really should have tried it first.
Scott Sauyet
@CrossEye
Apr 12 2015 23:29
I can't think of anything that will simplify your approach. Although we do have composeP and pipeP, Ramda hasn't done much to work with promises, I'm afraid.
Hardy Jones
@joneshf
Apr 12 2015 23:43
@lluft if I understand correctly, do you want the person to be passed implicitly to each of those functions? fetchEmail, and R.merge(person)?