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

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

There is a newer version: 0.8
Show 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
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)
    }


}