Example usage for java.util.function ToDoubleBiFunction applyAsDouble

List of usage examples for java.util.function ToDoubleBiFunction applyAsDouble

Introduction

In this page you can find the example usage for java.util.function ToDoubleBiFunction applyAsDouble.

Prototype

double applyAsDouble(T t, U u);

Source Link

Document

Applies this function to the given arguments.

Usage

From source file:Main.java

public static void main(String[] args) {
    ToDoubleBiFunction<Integer, Long> i = (x, y) -> Math.sin(x) + Math.sin(y);

    System.out.println(i.applyAsDouble(Integer.MAX_VALUE, Long.MAX_VALUE));
}

From source file:at.gridtec.lambda4j.function.bi.to.ToDoubleBiFunction2.java

/**
 * Calls the given {@link ToDoubleBiFunction} with the given arguments and returns its result.
 *
 * @param <T> The type of the first argument to the function
 * @param <U> The type of the second argument to the function
 * @param function The function to be called
 * @param t The first argument to the function
 * @param u The second argument to the function
 * @return The result from the given {@code ToDoubleBiFunction2}.
 * @throws NullPointerException If given argument is {@code null}
 *//*  w w  w  .  ja  va  2s.c  o  m*/
static <T, U> double call(@Nonnull final ToDoubleBiFunction<? super T, ? super U> function, T t, U u) {
    Objects.requireNonNull(function);
    return function.applyAsDouble(t, u);
}

From source file:at.gridtec.lambda4j.function.bi.to.ThrowableToDoubleBiFunction.java

/**
 * Returns a composed {@link ToDoubleBiFunction2} that first applies this function to its input, and then applies
 * the {@code recover} operation if a {@link Throwable} is thrown from this one. The {@code recover} operation is
 * represented by a curried operation which is called with throwable information and same arguments of this
 * function.//from  w  w w . j a v  a 2s  . c o  m
 *
 * @param recover The operation to apply if this function throws a {@code Throwable}
 * @return A composed {@link ToDoubleBiFunction2} that first applies this function to its input, and then applies
 * the {@code recover} operation if a {@code Throwable} is thrown from this one.
 * @throws NullPointerException If given argument or the returned enclosing function is {@code null}
 * @implSpec The implementation checks that the returned enclosing function from {@code recover} operation is not
 * {@code null}. If it is, then a {@link NullPointerException} with appropriate message is thrown.
 * @implNote If thrown {@code Throwable} is of type {@link Error}, it is thrown as-is and thus not passed to {@code
 * recover} operation.
 */
@Nonnull
default ToDoubleBiFunction2<T, U> recover(
        @Nonnull final Function<? super Throwable, ? extends ToDoubleBiFunction<? super T, ? super U>> recover) {
    Objects.requireNonNull(recover);
    return (t, u) -> {
        try {
            return this.applyAsDoubleThrows(t, u);
        } catch (Error e) {
            throw e;
        } catch (Throwable throwable) {
            final ToDoubleBiFunction<? super T, ? super U> function = recover.apply(throwable);
            Objects.requireNonNull(function,
                    () -> "recover returned null for " + throwable.getClass() + ": " + throwable.getMessage());
            return function.applyAsDouble(t, u);
        }
    };
}