Class | Proc
In: | lib/core/facets/proc/bind.rb lib/core/facets/proc/bind_to.rb lib/core/facets/proc/compose.rb lib/core/facets/proc/curry.rb lib/core/facets/proc/partial.rb lib/core/facets/proc/to_method.rb lib/core/facets/proc/update.rb
Parent: | Object

### Methods

* bind bind_to compose curry partial to_method

### External Aliases

call | -> | update
| Use a Proc as an observable. CREDIT: Tim Pease

### Public Instance methods

*(x)

Operator for Proc#compose and Integer#times_collect/of.

      a = lambda { |x| x + 4 }
      b = lambda { |y| y / 2 }

      (a * b).call(4)  #=> 6
      (b * a).call(4)  #=> 4

CREDIT: Dave

bind(object)

Bind a Proc to an object returning a Method.

NOTE: This version comes from Rails. The old Facets version used thread.rb, but I no longer think the implementaiton is thread critical. Please make a bug report if this proves wrong.

bind_to(object)

Bind a procedure to an object. This works wrapping instance_eval on the Proc object and then wrapping this in a new Proc.

       a = [1,2,3]
       p1 = Proc.new{ join(' ') }
       p2 = p1.bind_to(a)
       p2.call  #=> '1 2 3'

compose(g)

Returns a new proc that is the functional composition of two procs, in order.

      a = lambda { |x| x + 4 }
      b = lambda { |y| y / 2 }

      a.compose(b).call(4)  #=> 6
      b.compose(a).call(4)  #=> 4

CREDIT: Dave

curry(*args)

Curry Proc object into new Proc object.

TODO: Utilize Ruby 1.9‘s curry method.

partial(*args)

Convert a Proc object into new partial Proc object.

      a = proc { |a,b,c| a+b+c }
      b = a.partial(NA,2,NA)
      b[1,3] #=> 6

Note, the __ method, which used to be used in stay of NA, has been deprecated.

This method is similar to Proc#curry.

CREDT Trans

to_method(object, name=nil)

Convert Proc to method.

      object = Object.new

      function = lambda { |x| x + 1 }

      function.to_method(object, 'foo')

      object.foo(1)  #=> 2

[Validate]