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