Newer
Older
storm / src / main / java / com / ljunggren / storm / utils / ExceptionUtils.java
@aljunggren aljunggren on 2 Oct 2020 558 bytes Refactored to bubble exceptions
package com.ljunggren.storm.utils;

import java.util.function.Function;

public class ExceptionUtils {

    @FunctionalInterface
    public interface FunctionWithException<T, R, E extends Exception> {
        R apply(T t) throws E;
    }
    
    public static <T, R, E extends Exception> Function<T, R> rethrowFunction(FunctionWithException<T, R, E> fe) {
        return arg -> {
            try {
                return fe.apply(arg);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        };
    }    

}