Last Modified
2010-09-08 13:05:19 +0900
Requires

Description

Functor

Synopsis

By definition a Functor is simply a first class method, but these are common in the form of Method and Proc. So for Ruby a Functor is a bit more specialized as a Higher-order function or Metafunction. Essentally, a Functor can vary its behavior accorrding to the operation applied to it.

  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

Author

History

Todo

Copying

Copyright © 2004 Thomas Sawyer

Ruby License

This module is free software. You may use, modify, and/or redistribute this software under the same terms as Ruby.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.