Created
September 11, 2011 15:17
-
-
Save zonuexe/1209698 to your computer and use it in GitHub Desktop.
Rubyでカリー化函数
This file contains hidden or 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
curry = ->(f){ | |
args = [] | |
return rec = ->(a){ | |
args << a | |
return f.call(*args) if (args.length == f.arity) || (f.arity == -1) | |
return rec | |
} | |
} | |
if __FILE__ == $0 | |
func = ->(a,b,c){ a * b * c } | |
puts func[1,2,3] | |
puts curry[func][1][2][3] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment