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

org.ethelred.util.function.CheckedSupplier Maven / Gradle / Ivy

The newest version!
/* (C) 2024 */
package org.ethelred.util.function;

import java.util.function.Supplier;

/**
 * Checked wrapper for a Supplier.
 *
 * @param  The type returned by the operation
 * @param  A checked exception type that is thrown by the operation
 */
@FunctionalInterface
public interface CheckedSupplier {
    T get() throws E;

    default Supplier asUnchecked() {
        return () -> {
            try {
                return get();
            } catch (Throwable e) {
                throw new WrappedCheckedException(e);
            }
        };
    }

    static  Supplier unchecked(CheckedSupplier supplier) {
        return supplier.asUnchecked();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy