com.github.mperry.fg.ReaderM.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 fj.F
import groovy.transform.TypeChecked
import groovy.transform.TypeCheckingMode
/**
* Created by MarkPerry on 11/01/14.
*/
@TypeChecked
class ReaderM {
F function
ReaderM(F f) {
function = f
}
B f(A a) {
function.f(a)
}
@TypeChecked(TypeCheckingMode.SKIP)
static ReaderM lift(F f) {
new ReaderM(f)
}
@TypeChecked(TypeCheckingMode.SKIP)
static ReaderM lift(Closure f) {
new ReaderM(f as F)
}
@TypeChecked(TypeCheckingMode.SKIP)
def ReaderM map(F f) {
lift(Functions.andThen(function, f))
}
def ReaderM andThen(F f) {
map(f)
}
def ReaderM map(Closure c) {
map(c as F)
}
def ReaderM flatMap(F> f) {
lift({A a -> f.f(function.f(a)).f(a)} as F)
}
def ReaderM flatMap(Closure> c) {
flatMap(c as F)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy