[ruby-core:93168] [Ruby trunk Feature#15799] pipeline operator
From:
samuel@...
Date:
2019-06-16 00:49:26 UTC
List:
ruby-core #93168
Issue #15799 has been updated by ioquatix (Samuel Williams).
At first, I wasn't so sure about how to use such an operator, and honestly, the ASCII symbol `|>` is a bit jarring, but using a font with ligatures you get a better idea of how it's supposed to look, and it does look really great.
I have always desired right-assignment operator, and now I see it's being [worked on in separate issue](https://bugs.ruby-lang.org/issues/15921) so I'm really happy to see that.
I tried to think about some situations where the pipeline operator makes code more readable, and I think there are some areas where it is a great improvement.
```ruby
# Can't use do...end because it binds block to `puts`
logger.debug Async::Clock.measure {
# Slow things
}.round(2)
Async::Clock.measure do
# Slow things
end.round(2) |> logger.debug
```
Can we combine it with numbered arguments? (with single argument)
```ruby
Async::Clock.measure do
# Slow things
end.round(2) |> "It took #@s" |> logger.debug
```
Can we branch pipelines (maybe bad idea)?
```ruby
Async::Clock.measure do
# Slow things
end.round(2) |>
(@ > 1.0) ?
"It was slower than expected #@s" |> logger.debug :
"It was fast enough #@s" |> logger.info
```
Just throwing out some ideas.
----------------------------------------
Feature #15799: pipeline operator
https://bugs.ruby-lang.org/issues/15799#change-78609
* 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:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>