Skip to content

Instantly share code, notes, and snippets.

@defndaines
Last active August 29, 2015 14:07
Show Gist options
  • Save defndaines/18f76f4940ea3b7a1c3a to your computer and use it in GitHub Desktop.
Save defndaines/18f76f4940ea3b7a1c3a to your computer and use it in GitHub Desktop.
Ruby Curry Example
def three(a, b, c)
puts "a: #{a}, b: #{b}, c: #{c}"
end
def four(a, b, c, d)
puts "a: #{a}, b: #{b}, c: #{c}, d: #{d}"
end
three(:x, :y, :z)
# a: x, b: y, c: z
four(:w, :x, :y, :z)
# a: w, b: x, c: y, d: z
# And then curry all but the last argument.
san = method(:three).to_proc.curry.(:q).(:w)
yon = method(:four).to_proc.curry.(:z).(:x).(:c)
san.(:e)
# a: q, b: w, c: e
yon.(:v)
# a: z, b: x, c: c, d: v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment