com.aol.cyclops.functionaljava.comprehenders.StateComprehender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cyclops-functionaljava Show documentation
Show all versions of cyclops-functionaljava Show documentation
Converters and Comprehenders for FunctionalJava
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