Skip to content

Instantly share code, notes, and snippets.

@codertcet111
Created July 12, 2020 13:31
Show Gist options
  • Save codertcet111/9487b938eacf4b12d5e79dd2266795ed to your computer and use it in GitHub Desktop.
Save codertcet111/9487b938eacf4b12d5e79dd2266795ed to your computer and use it in GitHub Desktop.
def sum(a, *b)
a + b.inject(0) { |a, b| a + b}
end
sum_of_all = method(:sum).curry(3)
puts method(:sum)
puts "Normal Sum: #{sum(1,2,3)}"
puts "Curried Sum 👇:"
(1..3).each do |n|
sum_of_all = sum_of_all.call(n)
puts sum_of_all
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment