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

com.aol.cyclops.functionaljava.comprehenders.RightProjectionComprehender 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 java.util.function.Predicate;

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

import fj.data.Either;
import fj.data.Either.RightProjection;
import fj.data.Option;

public class RightProjectionComprehender implements ValueComprehender {
    @Override
    public Object filter(RightProjection t, Predicate p) {
        return t.filter(x -> p.test(x));
    }

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

    @Override
    public Object flatMap(RightProjection t, Function fn) {
        return t.bind(x -> fn.apply(x));
    }

    @Override
    public RightProjection of(Object o) {
        return Either.right(o)
                     .right();
    }

    @Override
    public RightProjection empty() {
        return Either.right(Option.none())
                     .right();
    }

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

    public Object resolveForCrossTypeFlatMap(Comprehender comp, RightProjection apply) {

        Option present = apply.toOption();
        if (present.isSome())
            return comp.of(present.some());
        else
            return comp.empty();

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy