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

io.smallrye.mutiny.converters.multi.ToSingleFailOnNull Maven / Gradle / Ivy

There is a newer version: 1.10.0
Show newest version
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 supplier;

    ToSingleFailOnNull(Supplier 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