Skip to content

Instantly share code, notes, and snippets.

@baroquebobcat
Last active December 31, 2015 18:49
Show Gist options
  • Save baroquebobcat/8029063 to your computer and use it in GitHub Desktop.
Save baroquebobcat/8029063 to your computer and use it in GitHub Desktop.
Symbol#curry, because one kind of curry just isn't enough
# 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