Last active
December 31, 2015 18:49
-
-
Save baroquebobcat/8029063 to your computer and use it in GitHub Desktop.
Symbol#curry, because one kind of curry just isn't enough
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
# add a curry method to symbol for evil/awesome symbol to proc powers. | |
class Symbol | |
def curry(n=nil) | |
->(*args) { | |
->(obj) {obj.send self, *args} | |
}.curry(n) | |
end | |
def call(*n) | |
curry.(*n) | |
end | |
end | |
%w[1 2 10 11].map(&:to_i.curry.(16)) | |
%w[1 2 10 11].map(&:to_i.(16)) | |
# => [1, 2, 16, 17] | |
%w[[email protected] [email protected]].map(&:split.curry.("@")) | |
%w[[email protected] [email protected]].map(&:split.("@")) | |
# => [["me", "example.com"], ["you", "example.org"]] | |
"cvs,is,cool,but | |
curried,is,better".each_line.map(&:split.(",")) | |
# But wait, there's more | |
# | |
# Module::call | |
class Module | |
def call method_name, *other_args | |
-> (iter) { self.send(method_name, [iter, *other_args]) } | |
end | |
end | |
list_o_json.map(&JSON.(:parse)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment