Class | Functor
In: | lib/facets/more/functor.rb
Parent: | Proc

# Functor

By definition a Functor is simply a first class method, but these are common in the form of Method and Proc. So here a Functor is a bit more specialized as a 1st class metafunction. Essentally, a Functor can vary its behavior accorrding to the operation applied to it.

## Synopsis

      f = Functor.new { |op, x| x.send(op, x) }
      f + 1  #=> 2
      f + 2  #=> 4
      f + 3  #=> 6
      f * 1  #=> 1
      f * 2  #=> 4
      f * 3  #=> 9

### Methods

method_missing new to_a to_proc

### Public Class methods

new(*arguments, &procedure)

Functor is created with a block the first argument of which is always the operator/method the functor will recieve. You can pass thru additional arguments along with the function that will be passed to the function as the initial parameters after the operator.

### Public Instance methods

method_missing(op, *args, &blk)

Any acton against the functor is processesd by the function.

to_a()

Returns the passthru arguments.

to_proc()

Returns the underlying procedure.

[Validate]