Functions { public static <R, V> Function0<V> compose(final Function0<R> first, final Function1<? super R, ? extends V> second) { if (null == first) { throw new NullPointerException(); } if (null == second) { throw new NullPointerException(); } return new Function0<V>() { @Override public V apply() { return second.apply(first.apply()); } }; }  static R invoke(final Function<R> f, final List<Object> args); @SuppressWarnings("unchecked") static Function0<R> buildInvocation(final Function<R> f, final List<Object> args); static Function0<R> identify(final Function0<R> f, final String identity); static Function1<T, R> identify(final Function1<T, R> f,
      final String identity); static Function2<T1, T2, R> identify(final Function2<T1, T2, R> f,
      final String identity); static Function3<T1, T2, T3, R> identify(final Function3<T1, T2, T3, R> f,
      final String identity); static Function4<T1, T2, T3, T4, R> identify(
      final Function4<T1, T2, T3, T4, R> f, final String identity); static Function5<T1, T2, T3, T4, T5, R> identify(
      final Function5<T1, T2, T3, T4, T5, R> f, final String identity); static Function0<V> compose(final Function0<R> first,
      final Function1<? super R, ? extends V> second); static Function1<T, V> compose(final Function1<? super T, ? extends R> first,
      final Function1<? super R, ? extends V> second); static Function2<T1, T2, V> compose(
      final Function2<? super T1, ? super T2, ? extends R> first,
      final Function1<? super R, ? extends V> second); static Function3<T1, T2, T3, V> compose(
      final Function3<? super T1, ? super T2, ? super T3, ? extends R> first,
      final Function1<? super R, ? extends V> second); static Function4<T1, T2, T3, T4, V> compose(
      final Function4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> first,
      final Function1<? super R, ? extends V> second); static Function5<T1, T2, T3, T4, T5, V> compose(
      final Function5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R>
          first, final Function1<? super R, ? extends V> second);  }
@Test public void testCompose0() { final String ret = randomUUID().toString(); Function0<String> f = new Function0<String>() { @Override public String apply() { return ret; } }; Function1<String, Integer> s = new Function1<String, Integer>() { @Override public Integer apply(final String t) { return t.length(); } }; Function0<Integer> composed = Functions.compose(f, s); final Integer expected = ret.length(); assertEquals(expected, composed.apply()); }
@Test public void testCompose1() { final String ret = randomUUID().toString(); Function1<String, String> f = new Function1<String, String>() { @Override public String apply(final String t) { return ret; } }; Function1<String, Integer> s = new Function1<String, Integer>() { @Override public Integer apply(final String t) { return t.length(); } }; Function1<String, Integer> composed = Functions.compose(f, s); final Integer expected = ret.length(); assertEquals(expected, composed.apply(randomUUID().toString())); }
@Test public void testCompose2() { final String ret = randomUUID().toString(); Function2<String, String, String> f = new Function2<String, String, String>() { @Override public String apply(final String t1, final String t2) { return ret; } }; Function1<String, Integer> s = new Function1<String, Integer>() { @Override public Integer apply(final String t) { return t.length(); } }; Function2<String, String, Integer> composed = Functions.compose(f, s); final Integer expected = ret.length(); assertEquals(expected, composed.apply(randomUUID().toString(), randomUUID().toString())); }
@Test public void testCompose3() { final String ret = randomUUID().toString(); Function3<String, String, String, String> f = new Function3<String, String, String, String>() { @Override public String apply(final String t1, final String t2, final String t3) { return ret; } }; Function1<String, Integer> s = new Function1<String, Integer>() { @Override public Integer apply(final String t) { return t.length(); } }; Function3<String, String, String, Integer> composed = Functions.compose(f, s); final Integer expected = ret.length(); assertEquals(expected, composed.apply(randomUUID().toString(), randomUUID().toString(), randomUUID().toString())); }
@Test public void testCompose4() { final String ret = randomUUID().toString(); Function4<String, String, String, String, String> f = new Function4<String, String, String, String, String>() { @Override public String apply(final String t1, final String t2, final String t3, final String t4) { return ret; } }; Function1<String, Integer> s = new Function1<String, Integer>() { @Override public Integer apply(final String t) { return t.length(); } }; Function4<String, String, String, String, Integer> composed = Functions.compose(f, s); final Integer expected = ret.length(); assertEquals(expected, composed.apply(randomUUID().toString(), randomUUID().toString(), randomUUID().toString(), randomUUID().toString())); }
@Test public void testCompose5() { final String ret = randomUUID().toString(); Function5<String, String, String, String, String, String> f = new Function5<String, String, String, String, String, String>() { @Override public String apply(final String t1, final String t2, final String t3, final String t4, final String t5) { return ret; } }; Function1<String, Integer> s = new Function1<String, Integer>() { @Override public Integer apply(final String t) { return t.length(); } }; Function5<String, String, String, String, String, Integer> composed = Functions.compose(f, s); final Integer expected = ret.length(); assertEquals(expected, composed.apply(randomUUID().toString(), randomUUID().toString(), randomUUID().toString(), randomUUID().toString(), randomUUID().toString())); }