1 /*******************************************************************************
2 * Copyright (c) 2016 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Semantum Oy - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.function;
14 import java.util.Objects;
16 import org.simantics.db.exception.DatabaseException;
19 * Represents a function that accepts one argument and produces a result that
20 * can throw database exceptions.
21 * This is the two-arity specialization of {@link DbFunction}.
23 * @param <T> the type of the first argument to the function
24 * @param <U> the type of the second argument to the function
25 * @param <R> the type of the result of the function
28 * @since 1.22.1 & 1.24.0
31 public interface DbBiFunction<T, U, R> {
34 * Applies this function to the given arguments.
36 * @param t the first function argument
37 * @param u the second function argument
38 * @return the function result
40 R apply(T t, U u) throws DatabaseException;
43 * Returns a composed function that first applies this function to
44 * its input, and then applies the {@code after} function to the result.
45 * If evaluation of either function throws an exception, it is relayed to
46 * the caller of the composed function.
48 * @param <V> the type of output of the {@code after} function, and of the
50 * @param after the function to apply after this function is applied
51 * @return a composed function that first applies this function and then
52 * applies the {@code after} function
53 * @throws NullPointerException if after is null
55 default <V> DbBiFunction<T, U, V> andThen(DbFunction<? super R, ? extends V> after) {
56 Objects.requireNonNull(after);
57 return (T t, U u) -> after.apply(apply(t, u));