[ruby-core:93133] [Ruby trunk Feature#15799] pipeline operator
From:
matz@...
Date:
2019-06-14 07:45:40 UTC
List:
ruby-core #93133
Issue #15799 has been updated by matz (Yukihiro Matsumoto).
Unlike JavaScript and Python (Lisp-1 like languages), Ruby is a Lisp-2 like language, in which methods and variable have separated namespaces. In Lisp-1 like languages, `f1 = function; f1()` calls `function` (single namespace).
In a Lisp-2 like language, ordinary (Elixir like) pipeline operator does not work, because it's harder to retrieve a method object in the language. Besides that, the receiver of Ruby methods can be considered as the first argument. So
```
a |> method1() |> method2() # or a.method1().method2()
```
can be considered as
```
method2(method1(a))
```
in other languages. So calling it a pipeline operator is not that out scoped.
Maybe we should call it a **chaining operator** and replace different combination of characters (`>>>` for example?) to avoid confusion.
Matz.
----------------------------------------
Feature #15799: pipeline operator
https://bugs.ruby-lang.org/issues/15799#change-78562
* 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>