
net.dongliu.commons.function.Suppliers Maven / Gradle / Ivy
package net.dongliu.commons.function;
import net.dongliu.commons.Result;
import java.util.Objects;
import java.util.function.Supplier;
/**
* Utils method for Supplier
*/
public class Suppliers {
/**
* Run a Supplier, and return Result.
*
* @throws NullPointerException if supplier if null, or supplier returns null.
*/
public static Result run(Supplier supplier) {
Objects.requireNonNull(supplier);
T value;
try {
value = supplier.get();
} catch (Throwable e) {
return Result.failed(e);
}
return Result.of(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy