/** * Returns a new function that composes this function and the specified function. * <p> * This returns a composed function that applies the input to this function * and then converts the result using the specified function. * * @param <V> the result type of second function * @param other the second function * @return the combined function, "this AND_THEN that" * @throws NullPointerException if the other function is null */ public default <V> ObjIntFunction<T, V> andThen(Function<? super R, ? extends V> other) { Objects.requireNonNull(other); return (obj, value) -> other.apply(apply(obj, value)); }
@Test(expectedExceptions = NullPointerException.class) public void test_andThen_null() { ObjIntFunction<Integer, String> fn1 = (a, b) -> a + "=" + b; fn1.andThen(null); }
@Override public <R> MarketDataBox<R> mapWithIndex(int scenarioCount, ObjIntFunction<T, R> fn) { List<R> perturbedValues = IntStream.range(0, scenarioCount) .mapToObj(idx -> fn.apply(value, idx)) .collect(toImmutableList()); return MarketDataBox.ofScenarioValues(perturbedValues); }
@Override public <R> MarketDataBox<R> mapWithIndex(int scenarioCount, ObjIntFunction<T, R> fn) { if (scenarioCount != getScenarioCount()) { throw new IllegalArgumentException( Messages.format( "Scenario count {} does not equal the scenario count of the value {}", scenarioCount, getScenarioCount())); } List<R> perturbedValues = IntStream.range(0, scenarioCount) .mapToObj(idx -> fn.apply(getValue(idx), idx)) .collect(toImmutableList()); return MarketDataBox.ofScenarioValues(perturbedValues); }