Issue #15799 has been updated by jeremyevans0 (Jeremy Evans).


baweaver (Brandon Weaver) wrote:
> But in summary, I  believe this feature could be substantially more expressive and powerful if it adjusted its lookup chain from directly calling on an object to searching the local scope for procs and methods.

The issue with that is it either leads to ambiguity or the requirement to remember the precedence:

```ruby
def double(n) n * 2 end
double = -> n { n << 4 }
x = [2]
def x.double; n.map{|x| x * 2} end

x
|> double
# [2, 2] or [2, 4] or [4]?
```

One possible lookup order is:

1. local variable, and call `call` on the local variable with LHS as the only argument
2. method call on `self` with LHS as additional argument
3. method call on LHS with no additional arguments

However, what about `method_missing`?  Logically, if you support a method call on self before a method call on the LHS, `method_missing` should be called on self if the method is not found.  In that case, you would never get to 3. unless you did something like `rescue NoMethodError` internally, which is not desired.

> I believe strongly that this would be a huge win for expressive power in the Ruby language if such a feature were fully implemented, but as it is now it is only an alias for what already exists.

While I'm overall against the addition of the pipeline operator (with or without R-assign operator), having identical operators with different precedences has a history in Ruby, with `&&`/`and` and `||`/`or`. 

----------------------------------------
Feature #15799: pipeline operator
https://bugs.ruby-lang.org/issues/15799#change-78557

* 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>