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

      T1 t1 = (T1) tuple.values().get(0);
      T2 t2 = (T2) tuple.values().get(1);

      return fn.apply(t1, t2);
    };
  }
Set of functions to process a {@link Tuple}
criteria/common/src/org/immutables/criteria/repository/Mappers.java