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

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

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