Created
May 3, 2017 19:34
-
-
Save fmnoise/d51957be6a309a32d778b902ac83846d to your computer and use it in GitHub Desktop.
Elixir-like pipeline in Ruby
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 Pipe | |
def self.[] value | |
self.new value | |
end | |
def initialize value | |
@value = value | |
end | |
def >> | |
self.class.new yield @value | |
end | |
def << | |
@value | |
end | |
end | |
# ending dots looks ugly but .>> looks uglier as for me | |
Pipe[1]. | |
>>{|i| i + 1}. | |
>>{|i| i * i}. | |
>>(&:to_s) | |
<< | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment