These are chat archives for ramda/ramda

Mar 2015
James Forbes
Mar 15 2015 02:32

Hey guys. I'm hoping you can help me with something.

Say you have a list of functions. And a list, where each item in the list is a single argument corresponding to a function in the other list.


fns = [fnA,fnB,fnC]
args = [argA,argB,argC]

is there a nice way to call each fn in fns with its corresponding argument. Like map with apply.

[ fnA(argA), fnB(argB), fnC(argC) ]

I tried ap. But it gives me back

[fnA(argA) fnA(argB) fnA(argC), fnB(argA), ... ]

Is this already somewhere and I am just not seeing it?

Scott Sauyet
Mar 15 2015 02:40
My first thought is R.zipWith(, args)
Mar 15 2015 02:41
Is Ramdajs library modeled after another specific functional language?
Scott Sauyet
Mar 15 2015 02:42
No, definitely not.
It tries to capture many of the core functions used in many languages, but it doesn't try to mimic the extent of any of them or even the normal way you might work with one.
Mar 15 2015 02:45
I was hoping you were going to say Haskell
James Forbes
Mar 15 2015 02:46
Thanks @CrossEye! I've never used zipWith. Bloody brilliant
files = ['a.js','b.js','c.js']
stats = [{  size: 0 }, {  size: 1 }, {  size: 2 }]

) //=> [ { filename:'a.js', size: 0 }, {filename:'b.js', size:1}, {filename:'c.js', size: 2}]
Scott Sauyet
Mar 15 2015 02:48
Haskell is an inspiration. For me it and Scheme are the greatest of my inspirations in the language. Others are inspired by Clojure, some Erlang. I haven't heard of contributors being particularly inspired by Scala or F#, but they might be out there. And we certainly know we owe a great debt to ML.

@JAForbes Actually, that can be simplified:

R.zipWith(R.assoc('filename'))(files, stats)

The call was there to deal with an arbitrary, unknown function. Here you can just pass the function to zipWith.

James Forbes
Mar 15 2015 09:38
Of course! Thanks. I used it today to write this I'll update that line later
I've not used zipWith before, I think I'll lean on it more generally
Martin Algesten
Mar 15 2015 09:48
is there a specific reason zip, zipWith works with only two arrays instead of a more general vagargs. currying perhaps?
Michael Hurley
Mar 15 2015 12:57

currying perhaps?

that's it

Raine Virta
Mar 15 2015 13:11
got a bit inspired by crosseye's and jaforbes' convo
Scott Sauyet
Mar 15 2015 14:19
@raine: looks like a nice, simple debugging tool. Thanks!
Sergey Lapin
Mar 15 2015 14:47
@raine simple and cool =)
Hardy Jones
Mar 15 2015 14:58
Those are both pretty neat
James Forbes
Mar 15 2015 23:50
@raine That's really cool.