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

com.github.andyshao.util.function.ExceptionableBiFunction Maven / Gradle / Ivy

The newest version!
package com.github.andyshao.util.function;

import com.github.andyshao.lang.Convert;
import com.github.andyshao.util.stream.RuntimeExceptionFactory;

import java.util.Objects;
import java.util.function.BiFunction;

/**
 * 
 * 
 * Title:
* Descript:
* Copyright: Copryright(c) May 28, 2019
* Encoding: UNIX UTF-8 * * @author Andy.Shao * * @param argument type one * @param argument type two * @param return type * @see BiFunction */ @FunctionalInterface public interface ExceptionableBiFunction { /** * apply * @param t left * @param u right * @return ret * @throws Exception any error */ R apply(T t, U u) throws Throwable; /** * to {@link BiFunction} * @param f error convert factory * @return {@link BiFunction} * @param left type * @param right type * @param return type */ static Convert, BiFunction> toBiFunction(RuntimeExceptionFactory f) { return input -> { return (t, u) -> { try { return input.apply(t, u); } catch (Throwable e) { throw f.build(e); } }; }; } /** * to {@link BiFunction} * @return {@link BiFunction} * @param left type * @param right type * @param return type */ static Convert, BiFunction> toBiFunction() { return toBiFunction(RuntimeExceptionFactory.DEFAULT); } /** * and then * @param after after * @return new {@link ExceptionableBiFunction} * @param return type */ default ExceptionableBiFunction andThen(ExceptionableFunction after) { Objects.requireNonNull(after); return (T t, U u) -> after.apply(apply(t, u)); } }