Last active
August 29, 2015 14:07
-
-
Save defndaines/18f76f4940ea3b7a1c3a to your computer and use it in GitHub Desktop.
Ruby Curry Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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