Module: YCombinator
- Defined in:
- lib/y_combinator.rb
Class Method Summary collapse
-
.y_combinator ⇒ Object
Returns a
lambdathat is the y combinator.
Class Method Details
.y_combinator ⇒ Object
Returns a lambda that is the y combinator. Y combinators are used to create anonymous recursively- defined functions. The y combinator should be applied to a partial function definition (this is the ‘recursion’ part). When the y combinator is applied to a partial function definition, it returns the partial function definition applied to itself. This means that an anonymous function can take itself as an argument and then refer to itself in its definition. This creates the recursion.
12 13 14 15 16 17 |
# File 'lib/y_combinator.rb', line 12 def self.y_combinator @y ||= ->(f) { ->(x) { f.(->(v) { x.(x).(v) }) }.( ->(x) { f.(->(v) { x.(x).(v) }) } ) } end |