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

com.aol.cyclops.reactor.comprehenders.MonoComprehender Maven / Gradle / Ivy

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

import java.util.function.Function;
import java.util.function.Predicate;

import com.aol.cyclops.control.FutureW;
import com.aol.cyclops.control.Xor;
import com.aol.cyclops.types.extensability.Comprehender;
import com.aol.cyclops.types.extensability.ValueComprehender;

import reactor.core.publisher.Mono;

public class MonoComprehender implements ValueComprehender {
    public Class getTargetClass() {
        return Mono.class;
    }

    @Override
    public Object filter(Mono o, Predicate p) {
        return FutureW.of(o.toFuture())
                      .filter(p);
    }

    @Override
    public Object map(Mono o, Function fn) {
        return o.map(fn);
    }

    @Override
    public Mono flatMap(Mono o, Function fn) {
        return Mono.from(o.flatMap(fn));
    }

    @Override
    public boolean instanceOfT(Object apply) {
        return apply instanceof Mono;
    }

    @Override
    public Mono of(Object o) {
        return Mono.just(o);
    }

    @Override
    public Mono empty() {
        return Mono.empty();
    }

    @Override
    public Object resolveForCrossTypeFlatMap(Comprehender comp, Mono apply) {
        Xor res = FutureW.of(apply.toFuture())
                                       .toXor();
        return res.isPrimary() ? comp.of(res.get()) : comp.empty();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy