Skip to content

Commit

Permalink
PoC of peek and tap in Tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Koziolek committed Oct 15, 2024
1 parent b8a2a95 commit 8f8a2fd
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 3 deletions.
40 changes: 40 additions & 0 deletions generator/Generator.sc
Original file line number Diff line number Diff line change
Expand Up @@ -1946,6 +1946,8 @@ def generateMainClasses(): Unit = {
case 2 => im.getType("java.util.function.BiFunction")
case _ => s"Function$i"
}
val checkedFunctionType = s"CheckedFunction$i"

val Comparator = im.getType("java.util.Comparator")
val Objects = im.getType("java.util.Objects")
val Seq = im.getType("io.vavr.collection.Seq")
Expand Down Expand Up @@ -2121,6 +2123,44 @@ def generateMainClasses(): Unit = {
}
""")}

${(i > 0).gen(xs"""
/$javadoc
* Apply consumer (function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
*/
public Tuple$i<$paramTypes> peek($functionType<$paramTypes, Void> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
${if (i == 1)
"consumer.apply(_1);"
else
s"consumer.apply($params);"
}
return this;
}

/$javadoc
* Apply checked consumer (checked function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
* @throws Throwable rethrow {@code consumer} throws
*/
public Tuple$i<$paramTypes> tap($checkedFunctionType<$paramTypes, Void> consumer) throws Throwable{
Objects.requireNonNull(consumer, "consumer is null");
${if (i == 1)
"consumer.apply(_1);"
else
s"consumer.apply($params);"
}
return this;
}
""")}


${(i > 1).gen(xs"""
/$javadoc
* Maps the components of this tuple using a mapper function for each component.
Expand Down
6 changes: 3 additions & 3 deletions src-gen/main/java/io/vavr/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -6081,7 +6081,7 @@ public static final class Case0<T, R> implements Case<T, R> {
private static final long serialVersionUID = 1L;

private final Pattern0<T> pattern;
private final Function<? super T, ? extends R> f;
private transient final Function<? super T, ? extends R> f;

private Case0(Pattern0<T> pattern, Function<? super T, ? extends R> f) {
this.pattern = pattern;
Expand All @@ -6104,7 +6104,7 @@ public static final class Case1<T, T1, R> implements Case<T, R> {
private static final long serialVersionUID = 1L;

private final Pattern1<T, T1> pattern;
private final Function<? super T1, ? extends R> f;
private transient final Function<? super T1, ? extends R> f;

private Case1(Pattern1<T, T1> pattern, Function<? super T1, ? extends R> f) {
this.pattern = pattern;
Expand All @@ -6127,7 +6127,7 @@ public static final class Case2<T, T1, T2, R> implements Case<T, R> {
private static final long serialVersionUID = 1L;

private final Pattern2<T, T1, T2> pattern;
private final BiFunction<? super T1, ? super T2, ? extends R> f;
private transient final BiFunction<? super T1, ? super T2, ? extends R> f;

private Case2(Pattern2<T, T1, T2> pattern, BiFunction<? super T1, ? super T2, ? extends R> f) {
this.pattern = pattern;
Expand Down
27 changes: 27 additions & 0 deletions src-gen/main/java/io/vavr/Tuple1.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ public <U1> Tuple1<U1> map(Function<? super T1, ? extends U1> mapper) {
return Tuple.of(mapper.apply(_1));
}

/**
* Apply consumer (function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
*/
public Tuple1<? super T1> peek(Function<? super T1, Void> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1);
return this;
}

/**
* Apply checked consumer (checked function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
* @throws Throwable rethrow {@code consumer} throws
*/
public Tuple1<? super T1> tap(CheckedFunction1<? super T1, Void> consumer) throws Throwable{
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1);
return this;
}

/**
* Transforms this tuple to an object of type U.
*
Expand Down
27 changes: 27 additions & 0 deletions src-gen/main/java/io/vavr/Tuple2.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,33 @@ public <U1, U2> Tuple2<U1, U2> map(BiFunction<? super T1, ? super T2, Tuple2<U1,
return mapper.apply(_1, _2);
}

/**
* Apply consumer (function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
*/
public Tuple2<? super T1, ? super T2> peek(BiFunction<? super T1, ? super T2, Void> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2);
return this;
}

/**
* Apply checked consumer (checked function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
* @throws Throwable rethrow {@code consumer} throws
*/
public Tuple2<? super T1, ? super T2> tap(CheckedFunction2<? super T1, ? super T2, Void> consumer) throws Throwable{
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2);
return this;
}

/**
* Maps the components of this tuple using a mapper function for each component.
*
Expand Down
27 changes: 27 additions & 0 deletions src-gen/main/java/io/vavr/Tuple3.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,33 @@ public <U1, U2, U3> Tuple3<U1, U2, U3> map(Function3<? super T1, ? super T2, ? s
return mapper.apply(_1, _2, _3);
}

/**
* Apply consumer (function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
*/
public Tuple3<? super T1, ? super T2, ? super T3> peek(Function3<? super T1, ? super T2, ? super T3, Void> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3);
return this;
}

/**
* Apply checked consumer (checked function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
* @throws Throwable rethrow {@code consumer} throws
*/
public Tuple3<? super T1, ? super T2, ? super T3> tap(CheckedFunction3<? super T1, ? super T2, ? super T3, Void> consumer) throws Throwable{
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3);
return this;
}

/**
* Maps the components of this tuple using a mapper function for each component.
*
Expand Down
27 changes: 27 additions & 0 deletions src-gen/main/java/io/vavr/Tuple4.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,33 @@ public <U1, U2, U3, U4> Tuple4<U1, U2, U3, U4> map(Function4<? super T1, ? super
return mapper.apply(_1, _2, _3, _4);
}

/**
* Apply consumer (function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
*/
public Tuple4<? super T1, ? super T2, ? super T3, ? super T4> peek(Function4<? super T1, ? super T2, ? super T3, ? super T4, Void> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4);
return this;
}

/**
* Apply checked consumer (checked function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
* @throws Throwable rethrow {@code consumer} throws
*/
public Tuple4<? super T1, ? super T2, ? super T3, ? super T4> tap(CheckedFunction4<? super T1, ? super T2, ? super T3, ? super T4, Void> consumer) throws Throwable{
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4);
return this;
}

/**
* Maps the components of this tuple using a mapper function for each component.
*
Expand Down
27 changes: 27 additions & 0 deletions src-gen/main/java/io/vavr/Tuple5.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,33 @@ public <U1, U2, U3, U4, U5> Tuple5<U1, U2, U3, U4, U5> map(Function5<? super T1,
return mapper.apply(_1, _2, _3, _4, _5);
}

/**
* Apply consumer (function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
*/
public Tuple5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5> peek(Function5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, Void> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4, _5);
return this;
}

/**
* Apply checked consumer (checked function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
* @throws Throwable rethrow {@code consumer} throws
*/
public Tuple5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5> tap(CheckedFunction5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, Void> consumer) throws Throwable{
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4, _5);
return this;
}

/**
* Maps the components of this tuple using a mapper function for each component.
*
Expand Down
27 changes: 27 additions & 0 deletions src-gen/main/java/io/vavr/Tuple6.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,33 @@ public <U1, U2, U3, U4, U5, U6> Tuple6<U1, U2, U3, U4, U5, U6> map(Function6<? s
return mapper.apply(_1, _2, _3, _4, _5, _6);
}

/**
* Apply consumer (function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
*/
public Tuple6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6> peek(Function6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, Void> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4, _5, _6);
return this;
}

/**
* Apply checked consumer (checked function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
* @throws Throwable rethrow {@code consumer} throws
*/
public Tuple6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6> tap(CheckedFunction6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, Void> consumer) throws Throwable{
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4, _5, _6);
return this;
}

/**
* Maps the components of this tuple using a mapper function for each component.
*
Expand Down
27 changes: 27 additions & 0 deletions src-gen/main/java/io/vavr/Tuple7.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,33 @@ public <U1, U2, U3, U4, U5, U6, U7> Tuple7<U1, U2, U3, U4, U5, U6, U7> map(Funct
return mapper.apply(_1, _2, _3, _4, _5, _6, _7);
}

/**
* Apply consumer (function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
*/
public Tuple7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7> peek(Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, Void> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4, _5, _6, _7);
return this;
}

/**
* Apply checked consumer (checked function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
* @throws Throwable rethrow {@code consumer} throws
*/
public Tuple7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7> tap(CheckedFunction7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, Void> consumer) throws Throwable{
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4, _5, _6, _7);
return this;
}

/**
* Maps the components of this tuple using a mapper function for each component.
*
Expand Down
27 changes: 27 additions & 0 deletions src-gen/main/java/io/vavr/Tuple8.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,33 @@ public <U1, U2, U3, U4, U5, U6, U7, U8> Tuple8<U1, U2, U3, U4, U5, U6, U7, U8> m
return mapper.apply(_1, _2, _3, _4, _5, _6, _7, _8);
}

/**
* Apply consumer (function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
*/
public Tuple8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8> peek(Function8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, Void> consumer) {
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4, _5, _6, _7, _8);
return this;
}

/**
* Apply checked consumer (checked function that produce java.lang.Void) for all of tuple elements.
*
* @param consumer the mapper function
* @return current tuple
* @throws NullPointerException if {@code mapper} is null
* @throws Throwable rethrow {@code consumer} throws
*/
public Tuple8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8> tap(CheckedFunction8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, Void> consumer) throws Throwable{
Objects.requireNonNull(consumer, "consumer is null");
consumer.apply(_1, _2, _3, _4, _5, _6, _7, _8);
return this;
}

/**
* Maps the components of this tuple using a mapper function for each component.
*
Expand Down

0 comments on commit 8f8a2fd

Please sign in to comment.