From: andrew@... Date: 2017-05-26T16:52:13+00:00 Subject: [ruby-core:81396] [Ruby trunk Feature#13600] yield_self should be chainable/composable Issue #13600 has been updated by avit (Andrew Vit). In case the description is unclear, the goal is to support something like this: ``` pipeline = (&:upcase).yield_self(&:reverse) "ruby".yield_self(pipeline) #=> "YRUB" ``` or else: ``` pipeline = (&:upcase) | (&:reverse) "ruby".yield_self(pipeline) #=> "YRUB" ``` ---------------------------------------- Feature #13600: yield_self should be chainable/composable https://bugs.ruby-lang.org/issues/13600#change-65108 * Author: avit (Andrew Vit) * Status: Open * 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: