Created
December 4, 2012 12:07
-
-
Save timruffles/4203147 to your computer and use it in GitHub Desktop.
ruby pipeline lambdas
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
class Proc | |
def |(g) | |
lambda {|*args| | |
g.(self.(*args)) | |
} | |
end | |
end | |
class Printer | |
def call(x) | |
puts "#{x}\n" | |
end | |
end | |
add_one = -> x { x+1 } | |
times_five = -> x { x*5 } | |
printer = Printer.new | |
(add_one | times_five | printer).(1) | |
(times_five | add_one | printer).(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment