TupleUtils { public static <T1, T2, R> Function<Tuple2<T1, T2>, R> function(BiFunction<T1, T2, R> function) { return tuple -> function.apply(tuple.getT1(), tuple.getT2()); } private  TupleUtils(); static Consumer<Tuple2<T1, T2>> consumer(BiConsumer<T1, T2> consumer); static Consumer<Tuple3<T1, T2, T3>> consumer(Consumer3<T1, T2, T3> consumer); static Consumer<Tuple4<T1, T2, T3, T4>> consumer(Consumer4<T1, T2, T3, T4> consumer); static Consumer<Tuple5<T1, T2, T3, T4, T5>> consumer(Consumer5<T1, T2, T3, T4, T5> consumer); static Consumer<Tuple6<T1, T2, T3, T4, T5, T6>> consumer(Consumer6<T1, T2, T3, T4, T5, T6> consumer); static Consumer<Tuple7<T1, T2, T3, T4, T5, T6, T7>> consumer(Consumer7<T1, T2, T3, T4, T5, T6, T7> consumer); static Consumer<Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>> consumer(Consumer8<T1, T2, T3, T4, T5, T6, T7, T8> consumer); static Function<Tuple2<T1, T2>, R> function(BiFunction<T1, T2, R> function); static Function<Tuple3<T1, T2, T3>, R> function(Function3<T1, T2, T3, R> function); static Function<Tuple4<T1, T2, T3, T4>, R> function(Function4<T1, T2, T3, T4, R> function); static Function<Tuple5<T1, T2, T3, T4, T5>, R> function(Function5<T1, T2, T3, T4, T5, R> function); static Function<Tuple6<T1, T2, T3, T4, T5, T6>, R> function(Function6<T1, T2, T3, T4, T5, T6, R> function); static Function<Tuple7<T1, T2, T3, T4, T5, T6, T7>, R> function(Function7<T1, T2, T3, T4, T5, T6, T7, R> function); static Function<Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>, R> function(Function8<T1, T2, T3, T4, T5, T6, T7, T8, R> function); static Predicate<Tuple2<T1, T2>> predicate(BiPredicate<T1, T2> predicate); static Predicate<Tuple3<T1, T2, T3>> predicate(Predicate3<T1, T2, T3> predicate); static Predicate<Tuple4<T1, T2, T3, T4>> predicate(Predicate4<T1, T2, T3, T4> predicate); static Predicate<Tuple5<T1, T2, T3, T4, T5>> predicate(Predicate5<T1, T2, T3, T4, T5> predicate); static Predicate<Tuple6<T1, T2, T3, T4, T5, T6>> predicate(Predicate6<T1, T2, T3, T4, T5, T6> predicate); static Predicate<Tuple7<T1, T2, T3, T4, T5, T6, T7>> predicate(Predicate7<T1, T2, T3, T4, T5, T6, T7> predicate); static Predicate<Tuple8<T1, T2, T3, T4, T5, T6, T7, T8>> predicate(Predicate8<T1, T2, T3, T4, T5, T6, T7, T8> predicate);  }
@Test public void customer() { StepVerifier.create(Flux .just(Tuples.of("John", "Doe", "NYC")) .map(TupleUtils.function(Customer::new)) ) .assertNext(c -> assertThat(c) .isInstanceOf(Customer.class) .hasFieldOrPropertyWithValue("fName", "John") .hasFieldOrPropertyWithValue("lName", "Doe") .hasFieldOrPropertyWithValue("address", "NYC") ) .verifyComplete(); }
@Test public void function2() { int result = TupleUtils .function((first, second) -> { assertThat(first).isEqualTo(1); assertThat(second).isEqualTo(2); return -1; }) .apply(Tuples.of(1, 2)); assertThat(result).isEqualTo(-1); }
@Test public void function3() { int result = TupleUtils .function((first, second, third) -> { assertThat(first).isEqualTo(1); assertThat(second).isEqualTo(2); assertThat(third).isEqualTo(3); return -1; }) .apply(Tuples.of(1, 2, 3)); assertThat(result).isEqualTo(-1); }
@Test public void function4() { int result = TupleUtils .function((first, second, third, fourth) -> { assertThat(first).isEqualTo(1); assertThat(second).isEqualTo(2); assertThat(third).isEqualTo(3); assertThat(fourth).isEqualTo(4); return -1; }) .apply(Tuples.of(1, 2, 3, 4)); assertThat(result).isEqualTo(-1); }
@Test public void function5() { int result = TupleUtils .function((first, second, third, fourth, fifth) -> { assertThat(first).isEqualTo(1); assertThat(second).isEqualTo(2); assertThat(third).isEqualTo(3); assertThat(fourth).isEqualTo(4); assertThat(fifth).isEqualTo(5); return -1; }) .apply(Tuples.of(1, 2, 3, 4, 5)); assertThat(result).isEqualTo(-1); }
@Test public void function6() { int result = TupleUtils .function((first, second, third, fourth, fifth, sixth) -> { assertThat(first).isEqualTo(1); assertThat(second).isEqualTo(2); assertThat(third).isEqualTo(3); assertThat(fourth).isEqualTo(4); assertThat(fifth).isEqualTo(5); assertThat(sixth).isEqualTo(6); return -1; }) .apply(Tuples.of(1, 2, 3, 4, 5, 6)); assertThat(result).isEqualTo(-1); }
@Test public void function7() { int result = TupleUtils .function((first, second, third, fourth, fifth, sixth, seventh) -> { assertThat(first).isEqualTo(1); assertThat(second).isEqualTo(2); assertThat(third).isEqualTo(3); assertThat(fourth).isEqualTo(4); assertThat(fifth).isEqualTo(5); assertThat(sixth).isEqualTo(6); assertThat(seventh).isEqualTo(7); return -1; }) .apply(Tuples.of(1, 2, 3, 4, 5, 6, 7)); assertThat(result).isEqualTo(-1); }
@Test public void function8() { int result = TupleUtils .function((first, second, third, fourth, fifth, sixth, seventh, eighth) -> { assertThat(first).isEqualTo(1); assertThat(second).isEqualTo(2); assertThat(third).isEqualTo(3); assertThat(fourth).isEqualTo(4); assertThat(fifth).isEqualTo(5); assertThat(sixth).isEqualTo(6); assertThat(seventh).isEqualTo(7); assertThat(eighth).isEqualTo(8); return -1; }) .apply(Tuples.of(1, 2, 3, 4, 5, 6, 7, 8)); assertThat(result).isEqualTo(-1); }