Skip to content

Instantly share code, notes, and snippets.

@tinco
Created March 12, 2010 23:08
Show Gist options
  • Save tinco/330914 to your computer and use it in GitHub Desktop.
Save tinco/330914 to your computer and use it in GitHub Desktop.
# f(f') {f(1)}, g(x1, x2, x3) {}, main{ f(g(2, 3)}
def curry(*params, &block)
lambda {|*curry_params| block.call(*(params.dup.concat(curry_params)))}
end
##usage:
g = lambda {|x1, x2, x3| puts "x1: #{x1}, x2: #{x2}. x3 #{x3}"}
f(1, 2, &g).call(3)
#=> x1: 1, x2: 2. x3 3
f = curry(1,2) {|x1, x2, x3| puts "x1 #{x1} x2 #{x2} x3 #{x3}"}
f.call(3)
#=> x1 1 x2 2 x3 3
a = curry(1, &g)
b = curry(2, &a)
c = curry(3, &b)
c.call
#=> x1 1 x2 2 x3 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment