Last active
October 21, 2016 19:06
-
-
Save kwstannard/323c4c86774a66f580fd055fc118b4f3 to your computer and use it in GitHub Desktop.
equivalent to elixer pipe in 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
class Proc | |
def <<(*args) | |
args = args.flatten if args.count == 1 | |
-> (*items) { self.call(*items, *args) } | |
end | |
end | |
adder = -> (*args) { args.inject(&:+) } | |
puts [1,2,3,4,5] | |
.map(&adder << 1) | |
.map(&adder << [10, 100]).inspect | |
class Method | |
def <<(*args) | |
args = args.flatten if args.count == 1 | |
-> (*items) { self.call(*items, *args) } | |
end | |
end | |
class Mathx | |
def self.product(*args) | |
args.inject(&:*) | |
end | |
def self.division(*args) | |
args.inject(&:/) | |
end | |
end | |
puts [1,2,3,4,5] | |
.map(&Mathx.method(:product) << 4) | |
.map(&Mathx.method(:division) << 2).inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment