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

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

There is a newer version: 0.8
Show newest version
package com.github.mperry.fg

import fj.F
import fj.P2
import groovy.transform.Canonical
import groovy.transform.TypeChecked

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

    StateInt(F> f) {
        run = f
    }

    def  StateInt flatMap(F> f) {
        new StateInt({ Integer s ->
            def p = run.f(s)
            def a = p._1()
            def s2 = p._2()

            def sib = f.f(a)
            sib.run.f(s2)
        } as F)
    }

}