[ruby-core:93144] [Ruby trunk Feature#15799] pipeline operator
From:
sean.m.huber@...
Date:
2019-06-14 16:56:01 UTC
List:
ruby-core #93144
Issue #15799 has been updated by shuber (Sean Huber).
@cichol Agreed! Here is a working proof of concept for an "operator-less" pipe operator which feels more natural in Ruby: https://github.com/lendinghome/pipe_operator
```ruby
# before
JSON.parse(Net::HTTP.get(URI.parse(url)))
# after
url.pipe { URI.parse; Net::HTTP.get; JSON.parse }
# with arguments and method chaining support
"https://api.github.com/repos/ruby/ruby".pipe do
URI.parse
Net::HTTP.get
JSON.parse.fetch("stargazers_count")
yield_self { |n| "Ruby has #{n} stars" }
Kernel.puts
end
#=> Ruby has 15120 stars
```
----------------------------------------
Feature #15799: pipeline operator
https://bugs.ruby-lang.org/issues/15799#change-78572
* Author: nobu (Nobuyoshi Nakada)
* Status: Closed
* Priority: Normal
* Assignee:
* Target version:
----------------------------------------
Implemented the pipeline operator `|>`, a topic of "ruby committers vs the world" in RubyKaigi 2019.
Also a casual idea of rightward assignment.
```ruby
1.. |> take 10 |> map {|e| e*2} |> (x)
p x #=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
```
https://github.com/nobu/ruby/tree/feature/pipeline
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>