All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mperry.fg.IdentityM.groovy Maven / Gradle / Ivy

The newest version!
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

/**
 * Created by MarkPerry on 9/01/14.
 */
@TypeChecked
@Canonical
class IdentityM extends Monad {

    A item

    private IdentityM(A a) {
        item = a
    }

    static IdentityM idUnit() {
        lift(Unit.unit())
    }

    static  IdentityM lift(B b) {
        new IdentityM(b)
    }

    @Override
    def  IdentityM flatMap(IdentityM mb, F> f) {
        f.f(mb.item)
    }

    @Override
    def  IdentityM unit(B b) {
        lift(b)
    }

    def  IdentityM flatMap(F> f) {
        flatMap(this, f)
    }


}