io.smallrye.mutiny.converters.multi.ToSingleFailOnNull Maven / Gradle / Ivy
package io.smallrye.mutiny.converters.multi;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import io.reactivex.Single;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.converters.uni.UniRxConverters;
import io.smallrye.mutiny.helpers.ParameterValidation;
public class ToSingleFailOnNull implements Function, Single> {
private final Supplier extends Throwable> supplier;
ToSingleFailOnNull(Supplier extends Throwable> supplier) {
this.supplier = ParameterValidation.nonNull(supplier, "supplier");
}
@Override
public Single apply(Multi multi) {
return multi.collect().first()
.onItem().ifNull().failWith(supplier)
.convert().with(UniRxConverters.toSingle())
.map(Optional::get);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy