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

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

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

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

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

/**
 * 
 * 
 * Title:
* Descript:
* Copyright: Copryright(c) May 30, 2019
* Encoding: UNIX UTF-8 * * @author Andy.Shao * * @param argument type * @param argument type * @param return type * @see ExceptionableBiFunction * @see BiFunction * @deprecated repeated */ @Deprecated(since = "5.0.0.RELEASE") public interface ThrowableBiFunction { /** * apply operation * @param t left type * @param u right type * @return ret * @throws Throwable any error */ R apply(T t, U u) throws Throwable; /** * to {@link ExceptionableBiFunction} * @return {@link ExceptionableBiFunction} * @param left type * @param right type * @param return type */ static Convert, ExceptionableBiFunction> toExceptionableBiFunction() { return input -> { return new ExceptionableBiFunction() { @Override public R apply(T t, U u) throws Throwable { try { return input.apply(t, u); } catch (Throwable e) { throw ThrowableException.convertToException(e); } } }; }; } /** * and then * @param after after {@link ThrowableFunction} * @return {@link ThrowableFunction} * @param data type */ default ThrowableBiFunction andThen(ThrowableFunction after) { Objects.requireNonNull(after); return (T t, U u) -> after.apply(apply(t, u)); } }