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

com.github.mperry.fg.SetExtension2.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 com.github.mperry.fg.typeclass.concrete.SetMonad
import fj.F
import fj.F2
import fj.F3
import fj.Unit
import fj.data.Stream
import groovy.transform.TypeChecked

/**
 * Created by MarkPerry on 12/04/2014.
 */
@TypeChecked
class SetExtension2 {

    static  Set create() {
        new HashSet()
    }

    static SetMonad monad() {
        new SetMonad()
    }

    static  Set fmap(Set ma, F f) {
        monad().fmap(f, ma)
    }


    static  Set apply(Set sa, Set> sf) {
        monad().apply(sf, sa)
    }

    static  Set flatMap(Set ma, F> f){
        monad().flatMap(ma, f)
    }

    static  Set map(Set ma, F f) {
        def result = this.create()
        for (A a: ma) {
            result.add(f.f(a))
        }
        result
    }

    static  Set map2(Set ma, Set mb, F2 f) {
        monad().map2(ma, mb, f)
    }

    static  Set to(Set ma, B b) {
        monad().to(ma, b)
    }

    static  Set skip(Set ma) {
        monad().skip(ma)
    }

    static  Set> replicateM(Set ma, Integer n) {
        monad().replicateM(n, ma)
    }

    static  Set liftM(Set ma, F f) {
        monad().liftM(ma, f)
    }

    static  Set liftM2(Set ma, Set mb, F2 f) {
        monad().liftM2(ma, mb, f)
    }

    static  Set liftM3(Set ma, Set mb, Set mc, F3 f) {
        monad().liftM3(ma, mb, mc, f)
    }

    static  Set ap(Set ma, Set> mf) {
        monad().ap(ma, mf)
    }

}