Project

General

Profile

Actions

Feature #6284

closed

Add composition for procs

Added by pabloh (Pablo Herrero) almost 12 years ago. Updated over 5 years ago.

Status:
Closed
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 1 (0 open1 closed)

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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0