These are chat archives for ramda/ramda

11th
May 2016
Dan Okkels Brendstrup
@bewildergeist
May 11 2016 07:58 UTC

Forgive a newb question, but for some reason this has me stumped: Mapping over an array and adding a prop to each object where the value is a function, and that function needs to be called with the current iteration object as an argument:

R.map(R.assoc("newProp", functionThatTakesAnArgument(currentItem)))

How might I accomplish that? 😁

Raine Virta
@raine
May 11 2016 08:01 UTC
R.map(obj => obj.newProp = functionThatTakesArgument(obj)) i don't see any better way
Dan Okkels Brendstrup
@bewildergeist
May 11 2016 08:07 UTC
@raine Makes perfect sense — I'm new enough to Ramda to assume that there must a special magic way to accomplish everything 😉 Thanks!
MySidesTheyAreGone
@MySidesTheyAreGone
May 11 2016 10:54 UTC
(n00b here) what's a better way of copying one property to another?
R.converge(R.assoc, [ R.always('downloadLink'), R.prop('link'), R.identity ])
Vladimir Starkov
@iamstarkov
May 11 2016 10:58 UTC
Actually that looks pretty good
MySidesTheyAreGone
@MySidesTheyAreGone
May 11 2016 10:59 UTC
Oh, it honestly seemed extremely convoluted compared to how simple the operation is O_O
Still, my perception of complexity is probably way off since I'm new to this
If it's good I'll just bundle it as a curried 3-ary function
Raine Virta
@raine
May 11 2016 11:01 UTC
it does look extremely convoluted
MySidesTheyAreGone
@MySidesTheyAreGone
May 11 2016 11:02 UTC
(out to lunch will read later, thanks in advance)
MySidesTheyAreGone
@MySidesTheyAreGone
May 11 2016 12:25 UTC
Well, apparently that's as good as it gets :) See you!
Lewis
@6ewis
May 11 2016 12:28 UTC
R.always
Lewis
@6ewis
May 11 2016 12:29 UTC
How/s R.always practical?
Raine Virta
@raine
May 11 2016 12:30 UTC
what?
Vladimir Starkov
@iamstarkov
May 11 2016 13:53 UTC
@6ewis R.Always seems stupid just at start,
Raine Virta
@raine
May 11 2016 13:55 UTC
(obj) => obj.downloadLink = obj.link
wow such readable
Vladimir Starkov
@iamstarkov
May 11 2016 14:01 UTC
@6ewis but when you start writing point-free code R.always is very helpful from time to time
@raine 👍
Brad Compton (he/him)
@Bradcomp
May 11 2016 14:05 UTC
@raine @MySidesTheyAreGone If you really need immutability you can still use assoc
obj => assoc('downloadLink', obj.link, obj)
Point being in this case it's the points free that makes it convoluted.
MySidesTheyAreGone
@MySidesTheyAreGone
May 11 2016 14:12 UTC
Thanks Brad. I don't need much of anything, I was just asking what's the best way to do it ramda-style.
Eventually I settled for this:
var copyTo = R.curry((dest, sourceFn, data) => R.converge(R.assoc, [
    R.always(dest),
    sourceFn,
    R.identity
])(data));
Not sure if stupid, but it lets me do anything from copyTo('link', R.prop('downloadLink')) to copyTo('link', R.pipe([...lots of stuff here...]))
MySidesTheyAreGone
@MySidesTheyAreGone
May 11 2016 14:17 UTC
It cut down some boilerplate :)
Tim Navrotskyy
@dypsilon
May 11 2016 15:31 UTC
Hi everyone, I often see the term "prelude" in the FP community. What does it mean?
Brad Compton (he/him)
@Bradcomp
May 11 2016 15:32 UTC
It's the standard library for Haskell
Tim Navrotskyy
@dypsilon
May 11 2016 15:33 UTC
Hm... why is it called prelude? Prelude to what?
Brad Compton (he/him)
@Bradcomp
May 11 2016 15:39 UTC
¯\_(ツ)_/¯
Tim Navrotskyy
@dypsilon
May 11 2016 16:34 UTC
This message was deleted
Tim Navrotskyy
@dypsilon
May 11 2016 18:08 UTC
I have this function (see the gist) and I want to refactor it to be completely pointfree, is there a way to work around the function on line 6, which needs two parameters?
Gabe Johnson
@gabejohnson
May 11 2016 18:58 UTC
@dypsilon it's called prelude because it is the foundational/introductory library
Tim Navrotskyy
@dypsilon
May 11 2016 19:12 UTC
@gabejohnson ah, I see
alonextou
@alonextou
May 11 2016 22:21 UTC
/rambot