@SuppressWarnings("unchecked")
  public static <R, T1, T2, T3, T4> Function<Tuple, R> fromTuple(MapperFunction4<T1, T2, T3, T4, R> fn) {
    return tuple -> {
      if (tuple.values().size() != 4) {
        throw new IllegalArgumentException(String.format("Expected tuple of size 4 got %d", tuple.values().size()));
      }

      T1 t1 = (T1) tuple.values().get(0);
      T2 t2 = (T2) tuple.values().get(1);
      T3 t3 = (T3) tuple.values().get(2);
      T4 t4 = (T4) tuple.values().get(3);
      return fn.apply(t1, t2, t3, t4);
    };
  }
Set of functions to process a {@link Tuple}
criteria/common/src/org/immutables/criteria/repository/Mappers.java