Project

General

Profile

Actions

Feature #13600

closed

yield_self should be chainable/composable

Added by avit (Andrew Vit) about 5 years ago. Updated almost 5 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:81395]

Description

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.


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #6284: Add composition for procsClosednobu (Nobuyoshi Nakada)Actions
Actions

Also available in: Atom PDF