Project

General

Profile

Feature #6284

Add composition for procs

Added by pabloh (Pablo Herrero) over 8 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:44303]

Description

It would be nice to be able to compose procs like functions in functional programming languages:

to_camel = :capitalize.to_proc
add_header = ->val {"Title: " + val}

format_as_title = add_header << to_camel << :strip

instead of:

format_as_title = lambda {|val| "Title: " + val.strip.capitalize }

It's pretty easy to implement in pure ruby:

class Proc
  def << block
    proc { |*args| self.call( block.to_proc.call(*args) ) }
  end
end

Files


Related issues

Related to Ruby master - Feature #13600: yield_self should be chainable/composableRejectedActions

Also available in: Atom PDF