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

cyclops.free.Yoneda Maven / Gradle / Ivy

The newest version!
package cyclops.free;

import com.oath.cyclops.hkt.Higher;
import com.oath.cyclops.hkt.DataWitness.yoneda;
import cyclops.typeclasses.functor.Functor;

import java.util.function.Function;

public interface Yoneda extends Higher, T> {



    public static  Yoneda of(Higher hkt, Functor functor){
        return new Yoneda(){
            @Override
            public  Higher apply(Function inner) {
               return functor.map(inner,hkt);
            }
        };


    }

     Higher apply(Function fn);

    default Higher run(){
        return apply(a->a);
    }

    default  Yoneda map(Function outer, Functor functor){
        return new Yoneda(){
            @Override
            public  Higher apply(Function inner) {
                return Yoneda.this.apply(i->inner.apply(outer.apply(i)));
            }
        };
    }
}