com.github.mperry.fg.Identity.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 com.github.mperry.fg.typeclass.Monad
import fj.F
import fj.Unit
import groovy.transform.Canonical
import groovy.transform.TypeChecked
import groovy.transform.TypeCheckingMode
/**
* Created by MarkPerry on 9/01/14.
*/
@TypeChecked
@Canonical
class Identity extends Monad {
A item
private Identity(A a) {
item = a
}
static Identity idUnit() {
lift(Unit.unit())
}
static Identity lift(B b) {
new Identity(b)
}
@TypeChecked(TypeCheckingMode.SKIP)
def Identity flatMap(Identity mb, F> f) {
f.f(mb.item)
}
@Override
def Identity unit(B b) {
lift(b)
}
def Identity flatMap(F> f) {
flatMap(this, f)
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy