[ruby-core:82562] [Ruby trunk Feature#13600][Rejected] yield_self should be chainable/composable

From: matz@...
Date: 2017-08-31 06:44:15 UTC
List: ruby-core #82562
Issue #13600 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected

Function composition should **not** be implemented by `yield_self`.

Matz.


----------------------------------------
Feature #13600: yield_self should be chainable/composable
https://bugs.ruby-lang.org/issues/13600#change-66375

* Author: avit (Andrew Vit)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
One of the main use cases that would make `yield_self` a helpful addition is to build functional pipelines (function composition). This is currently not possible since Proc/Lambda do not handle `yield_self` in the expected way.

I believe that `callable.yield_self(&other)` should build up a composition, something like this:


```
class Proc
  def yield_self(&other)
    proc { |input| other.call( self.call(input) ) }
  end
end
```

I originally proposed an example for this using pipe `|` syntax here:

https://bugs.ruby-lang.org/issues/10095#note-22

Maybe Proc should use `|` or `&` for this syntax instead of changing `yield_self` directly.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next