com.github.mperry.fg.YCombinator.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionalgroovy-main Show documentation
Show all versions of functionalgroovy-main Show documentation
FunctionalGroovy enhances FunctionalJava for Groovy
package com.github.mperry.fg
import groovy.transform.TypeChecked
/**
* Created by MarkPerry on 23/01/14.
*/
//@TypeChecked
class YCombinator {
/**
* Strict applicative order Y combinator
*
* (define Y
* (lambda (f)
* ((lambda (x) (x x))
* (lambda (x) (f (lambda (y) ((x x) y)))))))
*
* @param fx
* @return
*/
static def Y(Closure f) {
def h = { Closure x ->
// y is the value passed in
f { y ->
x(x)(y)
}
}
h(h)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy