I’m trying to wrap my head around functional programming in ruby and there doesn’t seem to be much good documentation out there.
Essentially, I’m trying to write a combine function that would have a Haskell type signature of:
[a] -> [a] -> (a -> a -> a) -> [a]
So
combine([1,2,3], [2,3,4], plus_func) => [3,5,7] combine([1,2,3], [2,3,4], multiply_func) => [2,6,12]
etc.
I found some stuff about using zip and map but that feels really ugly to use.
What would be the most ‘ruby’ way of implementing something like this?
Well, you said you know about zip and map so this probably isn’t helpful. But I’ll post just in case.
No, I don’t find it beautiful either.
edit – #ruby-lang @ irc.freenode.net suggests this:
or this, if you want to forward args: