Created
September 14, 2019 19:38
-
-
Save luchiago/3c94e24bbb7f1280bf1c15308ed7d12b to your computer and use it in GitHub Desktop.
Currying in ruby
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
#Allows a function accepts n parameters and turns it into a sequence of n functions, each of them take 1 parameter. | |
power_function = -> (x, z) { | |
(x) ** z | |
} | |
base = gets.to_i | |
raise_to_power = power_function.curry.(base) | |
power = gets.to_i | |
puts raise_to_power.(power) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment