Skip to content

Instantly share code, notes, and snippets.

@fmnoise
Created May 3, 2017 19:34
Show Gist options
  • Save fmnoise/d51957be6a309a32d778b902ac83846d to your computer and use it in GitHub Desktop.
Save fmnoise/d51957be6a309a32d778b902ac83846d to your computer and use it in GitHub Desktop.
Elixir-like pipeline in Ruby
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