Example #1
0
 public <U1, U2, U3, U4> Tuple4<U1, U2, U3, U4> map(
     Function1<? super T1, ? extends U1> f1,
     Function1<? super T2, ? extends U2> f2,
     Function1<? super T3, ? extends U3> f3,
     Function1<? super T4, ? extends U4> f4) {
   return map(
       (t1, t2, t3, t4) -> Tuple.of(f1.apply(t1), f2.apply(t2), f3.apply(t3), f4.apply(t4)));
 }
Example #2
0
 @Test
 public void shouldMapComponents() {
   final Tuple4<Object, Object, Object, Object> tuple = createTuple();
   final Function1<Object, Object> f1 = Function1.identity();
   final Function1<Object, Object> f2 = Function1.identity();
   final Function1<Object, Object> f3 = Function1.identity();
   final Function1<Object, Object> f4 = Function1.identity();
   final Tuple4<Object, Object, Object, Object> actual = tuple.map(f1, f2, f3, f4);
   assertThat(actual).isEqualTo(tuple);
 }
Example #3
0
 @Override
 public <U> Array<T> sortBy(
     Comparator<? super U> comparator, Function<? super T, ? extends U> mapper) {
   final Function<? super T, ? extends U> domain = Function1.of(mapper::apply).memoized();
   return toJavaStream()
       .sorted((e1, e2) -> comparator.compare(domain.apply(e1), domain.apply(e2)))
       .collect(collector());
 }
Example #4
0
 /**
  * Lifts the given {@code partialFunction} into a total function that returns an {@code Option}
  * result.
  *
  * @param partialFunction a function that is not defined for all values of the domain (e.g. by
  *     throwing)
  * @param <R> return type
  * @param <T1> 1st argument
  * @return a function that applies arguments to the given {@code partialFunction} and returns
  *     {@code Some(result)} if the function is defined for the given arguments, and {@code None}
  *     otherwise.
  */
 static <T1, R> Function1<T1, Option<R>> lift(Function1<T1, R> partialFunction) {
   return (t1) -> Try.of(() -> partialFunction.apply(t1)).getOption();
 }
Example #5
0
 /**
  * Returns a composed function that first applies this Function2 to the given argument and then
  * applies {@linkplain Function1} {@code after} to the result.
  *
  * @param <V> return type of after
  * @param after the function applied after this
  * @return a function composed of this and after
  * @throws NullPointerException if after is null
  */
 default <V> Function2<T1, T2, V> andThen(Function1<? super R, ? extends V> after) {
   Objects.requireNonNull(after, "after is null");
   return (t1, t2) -> after.apply(apply(t1, t2));
 }
Example #6
0
 /**
  * Returns a composed function that first applies the {@linkplain Function1} {@code before} the
  * given argument and then applies this Function1 to the result.
  *
  * @param <V> argument type of before
  * @param before the function applied before this
  * @return a function composed of before and this
  * @throws NullPointerException if before is null
  */
 default <V> Function1<V, R> compose(Function1<? super V, ? extends T1> before) {
   Objects.requireNonNull(before, "before is null");
   return v -> apply(before.apply(v));
 }
Example #7
0
 public <U1> Tuple1<U1> map(Function1<? super T1, ? extends U1> f) {
   return new Tuple1<>(f.apply(_1));
 }