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

com.aol.cyclops.functionaljava.comprehenders.StateComprehender Maven / Gradle / Ivy

There is a newer version: 9.0.0-MI7
Show newest version
package com.aol.cyclops.functionaljava.comprehenders;

import java.util.function.Function;

import com.aol.cyclops.types.extensability.Comprehender;
import com.aol.cyclops.types.extensability.ValueComprehender;

import fj.data.Option;
import fj.data.State;

public class StateComprehender implements ValueComprehender {

    @Override
    public Object resolveForCrossTypeFlatMap(Comprehender comp, State apply) {
        return comp.of(apply.run(null)
                            ._2());
    }

    @Override
    public Object map(State t, Function fn) {
        return t.map(r -> fn.apply(r));
    }

    @Override
    public Object flatMap(State t, Function fn) {
        return t.flatMap(r -> fn.apply(r));
    }

    @Override
    public State of(Object o) {
        return State.constant(o);
    }

    @Override
    public State empty() {
        return State.constant(Option.none());
    }

    @Override
    public Class getTargetClass() {
        return State.class;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy