diff --git a/vavr/generator/Generator.scala b/vavr/generator/Generator.scala
index 7bf4464945..2060fdce54 100644
--- a/vavr/generator/Generator.scala
+++ b/vavr/generator/Generator.scala
@@ -743,6 +743,151 @@ def generateMainClasses(): Unit = {
"""
}
+ def genLazyFor(im: ImportManager, packageName: String, className: String): String = {
+ xs"""
+ ${
+ monadicTypesFor
+ .filterNot(_ == "Iterable")
+ .gen(mtype => (2 to N).gen(i => {
+ val forClassName = s"ForLazy$i$mtype"
+ val isComplex = monadicTypesThatNeedParameter.contains(mtype)
+ val parameterInset = if (isComplex) "L, " else ""
+ val generics = parameterInset + (1 to i).gen(j => s"T$j")(", ")
+
+ val params = (1 to i).gen { j =>
+ if (j == 1)
+ s"$mtype<${parameterInset}T1> ts1"
+ else {
+ val inputTypes = (1 until j).gen(k => s"? super T$k")(", ")
+ s"Function${j - 1}<$inputTypes, $mtype<${parameterInset}T$j>> ts$j"
+ }
+ }(", ")
+
+ val ctorArgs = (1 to i).gen(j => s"ts$j")(", ")
+
+ xs"""
+ /$javadoc
+ * Creates a lazy {@code For}-comprehension over ${i.numerus(mtype)}.
+ *
+ *
The first argument ({@code ts1}) is the initial ${mtype}. Each subsequent
+ * argument ({@code ts2} .. {@code ts$i}) is a function that receives all values
+ * bound so far and returns the next ${mtype}. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ ${(0 to i).gen(j => if (j == 0) "*" else s"* @param ts$j the ${j.ordinal} ${mtype}")("\n")}
+ ${if (isComplex) s"* @param the common left-hand type of all ${mtype}s\n" else ""}
+ ${(1 to i).gen(j => s"* @param the component type of the ${j.ordinal} ${mtype}")("\n")}
+ * @return a new {@code $forClassName} builder of arity $i
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static <$generics> $forClassName<$generics> For($params) {
+ ${(1 to i).gen(j => xs"""$Objects.requireNonNull(ts$j, "ts$j is null");""")("\n")}
+ return new $forClassName<>($ctorArgs);
+ }
+ """
+ })("\n\n"))("\n\n")
+ }
+
+ ${
+ monadicTypesFor
+ .filterNot(_ == "Iterable")
+ .gen(mtype => (2 to N).gen(i => {
+ val rtype = mtype
+ val forClassName = s"ForLazy$i$mtype"
+ val parameterInset = if (monadicTypesThatNeedParameter.contains(mtype)) "L, " else ""
+ val generics = parameterInset + (1 to i).gen(j => s"T$j")(", ")
+
+ val fields = (1 to i).gen { j =>
+ if (j == 1)
+ s"private final $mtype<${parameterInset}T1> ts1;"
+ else {
+ val inputTypes = (1 until j).gen(k => s"? super T$k")(", ")
+ s"private final Function${j - 1}<$inputTypes, $mtype<${parameterInset}T$j>> ts$j;"
+ }
+ }("\n")
+
+ val ctorParams = (1 to i).gen { j =>
+ if (j == 1)
+ s"$mtype<${parameterInset}T1> ts1"
+ else {
+ val inputTypes = (1 until j).gen(k => s"? super T$k")(", ")
+ s"Function${j - 1}<$inputTypes, $mtype<${parameterInset}T$j>> ts$j"
+ }
+ }(", ")
+
+ val assignments = (1 to i).gen(j => s"this.ts$j = ts$j;")("\n")
+
+ val yieldBody = {
+ def nestedLambda(j: Int): String = {
+ val base = " " * 23
+ val indent = " " * (j + 1)
+ if (j == i) {
+ val argsList = (1 to i).map(k => s"t$k").mkString(", ")
+ val inputArgs = (1 until i).map(k => s"t$k").mkString(", ")
+ s"ts$i.apply($inputArgs).map(t$i -> f.apply($argsList))"
+ } else if (j == 1) {
+ s"ts1.flatMap(t1 -> {\n" +
+ s"${base}${indent} return ${nestedLambda(j + 1)};\n" +
+ s"${base}${indent}})"
+ } else {
+ val inputArgs = (1 until j).map(k => s"t$k").mkString(", ")
+ s"ts$j.apply($inputArgs).flatMap(t$j -> {\n" +
+ s"${base}${indent} return ${nestedLambda(j + 1)};\n" +
+ s"${base}${indent}})"
+ }
+ }
+
+ nestedLambda(1)
+ }
+
+ xs"""
+ /$javadoc
+ * A lazily evaluated {@code For}-comprehension with ${i.numerus(mtype)}.
+ *
+ * Constructed via {@code For(...)} and evaluated by calling {@code yield(...)}.
+ * Construction is side-effect free; underlying ${i.plural(mtype)} are traversed
+ * only when {@code yield(...)} is invoked.
+ *
+ ${if (monadicTypesThatNeedParameter.contains(mtype)) s"* @param the common left-hand type of all ${mtype}s\n" else ""}
+ ${(1 to i).gen(j => s"* @param the component type of the ${j.ordinal} ${mtype}")("\n")}
+ */
+ public static class $forClassName<$generics> {
+
+ $fields
+
+ private $forClassName($ctorParams) {
+ $assignments
+ }
+
+ /$javadoc
+ * Produces results by mapping the Cartesian product of all bound values.
+ *
+ * Evaluation is lazy and delegated to the underlying ${i.plural(mtype)} by
+ * composing {@code flatMap} and {@code map} chains.
+ *
+ * @param f a function mapping a tuple of bound values to a result
+ * @param the element type of the resulting {@code $rtype}
+ * @return an {@code $rtype} containing mapped results
+ * @throws NullPointerException if {@code f} is {@code null}
+ */
+ public $rtype<${parameterInset}R> yield(${
+ if (i == 2)
+ s"BiFunction super T1, ? super T2, ? extends R>"
+ else
+ s"Function$i<${(1 to i).map(j => s"? super T$j").mkString(", ")}, ? extends R>"
+ } f) {
+ $Objects.requireNonNull(f, "f is null");
+ return $yieldBody;
+ }
+ }
+ """
+ })("\n\n"))("\n\n")
+ }
+ """
+ }
+
+
def genFor(im: ImportManager, packageName: String, className: String): String = {
xs"""
//
@@ -1440,6 +1585,8 @@ def generateMainClasses(): Unit = {
${genFor(im, packageName, className)}
+ ${genLazyFor(im, packageName, className)}
+
${genMatch(im, packageName, className)}
}
"""
@@ -2975,8 +3122,27 @@ def generateTestClasses(): Unit = {
).yield(${(i > 1).gen("(")}${(1 to i).gen(j => s"i$j")(", ")}${(i > 1).gen(")")} -> ${(1 to i).gen(j => s"i$j")(" + ")});
$assertThat(result.get()).isEqualTo(${(1 to i).sum});
}
+
+ @$test
+ public void shouldIterateLazyFor$mtype$i() {
+ final $mtype<${parameterInset}Integer> result = For(
+ ${(1 to i).gen(j => if (j == 1) {
+ s"$mtype.${builderName}($j)"
+ } else {
+ val args = (1 until j).map(k => s"r$k").mkString(", ")
+ val argsUsed = (1 until j).map(k => s"r$k").mkString(" + ")
+ s"($args) -> $mtype.${builderName}(${argsUsed} + $j)"
+ } )(",\n")}
+ ).yield(${(i > 1).gen("(")}${(1 to i).gen(j => s"i$j")(", ")}${(i > 1).gen(")")} -> ${(1 to i).gen(j => s"i$j")(" + ")});
+
+ // Each step builds on the sum of all previous results plus its index
+ // This forms a sequence rₙ = 2ⁿ - 1, and the yield sums all rᵢ.
+ // Hence total = Σ(2ⁱ - 1) for i = 1..n = (2ⁿ⁺¹ - 2) - n
+ assertThat(result.get()).isEqualTo((1 << ($i + 1)) - 2 - $i);
+ }
"""})("\n\n"))("\n\n")}
+
${monadicFunctionTypesFor.gen(mtype => (1 to N).gen(i => { xs"""
@$test
public void shouldIterateFor$mtype$i() {
diff --git a/vavr/src-gen/main/java/io/vavr/API.java b/vavr/src-gen/main/java/io/vavr/API.java
index 99c8a182b1..f1653a5afa 100644
--- a/vavr/src-gen/main/java/io/vavr/API.java
+++ b/vavr/src-gen/main/java/io/vavr/API.java
@@ -5740,6 +5740,3702 @@ public Validation yield(Function8 super T1, ? super T2, ? super T3,
}
+ /**
+ * Creates a lazy {@code For}-comprehension over two Options.
+ *
+ * The first argument ({@code ts1}) is the initial Option. Each subsequent
+ * argument ({@code ts2} .. {@code ts2}) is a function that receives all values
+ * bound so far and returns the next Option. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Option
+ * @param ts2 the 2nd Option
+
+ * @param the component type of the 1st Option
+ * @param the component type of the 2nd Option
+ * @return a new {@code ForLazy2Option} builder of arity 2
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy2Option For(Option ts1, Function1 super T1, Option> ts2) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ return new ForLazy2Option<>(ts1, ts2);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over three Options.
+ *
+ * The first argument ({@code ts1}) is the initial Option. Each subsequent
+ * argument ({@code ts2} .. {@code ts3}) is a function that receives all values
+ * bound so far and returns the next Option. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Option
+ * @param ts2 the 2nd Option
+ * @param ts3 the 3rd Option
+
+ * @param the component type of the 1st Option
+ * @param the component type of the 2nd Option
+ * @param the component type of the 3rd Option
+ * @return a new {@code ForLazy3Option} builder of arity 3
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy3Option For(Option ts1, Function1 super T1, Option> ts2, Function2 super T1, ? super T2, Option> ts3) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ return new ForLazy3Option<>(ts1, ts2, ts3);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 4 Options.
+ *
+ * The first argument ({@code ts1}) is the initial Option. Each subsequent
+ * argument ({@code ts2} .. {@code ts4}) is a function that receives all values
+ * bound so far and returns the next Option. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Option
+ * @param ts2 the 2nd Option
+ * @param ts3 the 3rd Option
+ * @param ts4 the 4th Option
+
+ * @param the component type of the 1st Option
+ * @param the component type of the 2nd Option
+ * @param the component type of the 3rd Option
+ * @param the component type of the 4th Option
+ * @return a new {@code ForLazy4Option} builder of arity 4
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy4Option For(Option ts1, Function1 super T1, Option> ts2, Function2 super T1, ? super T2, Option> ts3, Function3 super T1, ? super T2, ? super T3, Option> ts4) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ return new ForLazy4Option<>(ts1, ts2, ts3, ts4);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 5 Options.
+ *
+ * The first argument ({@code ts1}) is the initial Option. Each subsequent
+ * argument ({@code ts2} .. {@code ts5}) is a function that receives all values
+ * bound so far and returns the next Option. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Option
+ * @param ts2 the 2nd Option
+ * @param ts3 the 3rd Option
+ * @param ts4 the 4th Option
+ * @param ts5 the 5th Option
+
+ * @param the component type of the 1st Option
+ * @param the component type of the 2nd Option
+ * @param the component type of the 3rd Option
+ * @param the component type of the 4th Option
+ * @param the component type of the 5th Option
+ * @return a new {@code ForLazy5Option} builder of arity 5
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy5Option For(Option ts1, Function1 super T1, Option> ts2, Function2 super T1, ? super T2, Option> ts3, Function3 super T1, ? super T2, ? super T3, Option> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Option> ts5) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ return new ForLazy5Option<>(ts1, ts2, ts3, ts4, ts5);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 6 Options.
+ *
+ * The first argument ({@code ts1}) is the initial Option. Each subsequent
+ * argument ({@code ts2} .. {@code ts6}) is a function that receives all values
+ * bound so far and returns the next Option. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Option
+ * @param ts2 the 2nd Option
+ * @param ts3 the 3rd Option
+ * @param ts4 the 4th Option
+ * @param ts5 the 5th Option
+ * @param ts6 the 6th Option
+
+ * @param the component type of the 1st Option
+ * @param the component type of the 2nd Option
+ * @param the component type of the 3rd Option
+ * @param the component type of the 4th Option
+ * @param the component type of the 5th Option
+ * @param the component type of the 6th Option
+ * @return a new {@code ForLazy6Option} builder of arity 6
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy6Option For(Option ts1, Function1 super T1, Option> ts2, Function2 super T1, ? super T2, Option> ts3, Function3 super T1, ? super T2, ? super T3, Option> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Option> ts5, Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, Option> ts6) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ Objects.requireNonNull(ts6, "ts6 is null");
+ return new ForLazy6Option<>(ts1, ts2, ts3, ts4, ts5, ts6);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 7 Options.
+ *
+ * The first argument ({@code ts1}) is the initial Option. Each subsequent
+ * argument ({@code ts2} .. {@code ts7}) is a function that receives all values
+ * bound so far and returns the next Option. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Option
+ * @param ts2 the 2nd Option
+ * @param ts3 the 3rd Option
+ * @param ts4 the 4th Option
+ * @param ts5 the 5th Option
+ * @param ts6 the 6th Option
+ * @param ts7 the 7th Option
+
+ * @param the component type of the 1st Option
+ * @param the component type of the 2nd Option
+ * @param the component type of the 3rd Option
+ * @param the component type of the 4th Option
+ * @param the component type of the 5th Option
+ * @param the component type of the 6th Option
+ * @param the component type of the 7th Option
+ * @return a new {@code ForLazy7Option} builder of arity 7
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy7Option For(Option ts1, Function1 super T1, Option> ts2, Function2 super T1, ? super T2, Option> ts3, Function3 super T1, ? super T2, ? super T3, Option> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Option> ts5, Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, Option> ts6, Function6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, Option> ts7) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ Objects.requireNonNull(ts6, "ts6 is null");
+ Objects.requireNonNull(ts7, "ts7 is null");
+ return new ForLazy7Option<>(ts1, ts2, ts3, ts4, ts5, ts6, ts7);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 8 Options.
+ *
+ * The first argument ({@code ts1}) is the initial Option. Each subsequent
+ * argument ({@code ts2} .. {@code ts8}) is a function that receives all values
+ * bound so far and returns the next Option. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Option
+ * @param ts2 the 2nd Option
+ * @param ts3 the 3rd Option
+ * @param ts4 the 4th Option
+ * @param ts5 the 5th Option
+ * @param ts6 the 6th Option
+ * @param ts7 the 7th Option
+ * @param ts8 the 8th Option
+
+ * @param the component type of the 1st Option
+ * @param the component type of the 2nd Option
+ * @param the component type of the 3rd Option
+ * @param the component type of the 4th Option
+ * @param the component type of the 5th Option
+ * @param the component type of the 6th Option
+ * @param the component type of the 7th Option
+ * @param the component type of the 8th Option
+ * @return a new {@code ForLazy8Option} builder of arity 8
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy8Option For(Option ts1, Function1 super T1, Option> ts2, Function2 super T1, ? super T2, Option> ts3, Function3 super T1, ? super T2, ? super T3, Option> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Option> ts5, Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, Option> ts6, Function6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, Option> ts7, Function7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, Option> ts8) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ Objects.requireNonNull(ts6, "ts6 is null");
+ Objects.requireNonNull(ts7, "ts7 is null");
+ Objects.requireNonNull(ts8, "ts8 is null");
+ return new ForLazy8Option<>(ts1, ts2, ts3, ts4, ts5, ts6, ts7, ts8);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over two Futures.
+ *
+ * The first argument ({@code ts1}) is the initial Future. Each subsequent
+ * argument ({@code ts2} .. {@code ts2}) is a function that receives all values
+ * bound so far and returns the next Future. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Future
+ * @param ts2 the 2nd Future
+
+ * @param the component type of the 1st Future
+ * @param the component type of the 2nd Future
+ * @return a new {@code ForLazy2Future} builder of arity 2
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy2Future For(Future ts1, Function1 super T1, Future> ts2) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ return new ForLazy2Future<>(ts1, ts2);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over three Futures.
+ *
+ * The first argument ({@code ts1}) is the initial Future. Each subsequent
+ * argument ({@code ts2} .. {@code ts3}) is a function that receives all values
+ * bound so far and returns the next Future. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Future
+ * @param ts2 the 2nd Future
+ * @param ts3 the 3rd Future
+
+ * @param the component type of the 1st Future
+ * @param the component type of the 2nd Future
+ * @param the component type of the 3rd Future
+ * @return a new {@code ForLazy3Future} builder of arity 3
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy3Future For(Future ts1, Function1 super T1, Future> ts2, Function2 super T1, ? super T2, Future> ts3) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ return new ForLazy3Future<>(ts1, ts2, ts3);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 4 Futures.
+ *
+ * The first argument ({@code ts1}) is the initial Future. Each subsequent
+ * argument ({@code ts2} .. {@code ts4}) is a function that receives all values
+ * bound so far and returns the next Future. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Future
+ * @param ts2 the 2nd Future
+ * @param ts3 the 3rd Future
+ * @param ts4 the 4th Future
+
+ * @param the component type of the 1st Future
+ * @param the component type of the 2nd Future
+ * @param the component type of the 3rd Future
+ * @param the component type of the 4th Future
+ * @return a new {@code ForLazy4Future} builder of arity 4
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy4Future For(Future ts1, Function1 super T1, Future> ts2, Function2 super T1, ? super T2, Future> ts3, Function3 super T1, ? super T2, ? super T3, Future> ts4) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ return new ForLazy4Future<>(ts1, ts2, ts3, ts4);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 5 Futures.
+ *
+ * The first argument ({@code ts1}) is the initial Future. Each subsequent
+ * argument ({@code ts2} .. {@code ts5}) is a function that receives all values
+ * bound so far and returns the next Future. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Future
+ * @param ts2 the 2nd Future
+ * @param ts3 the 3rd Future
+ * @param ts4 the 4th Future
+ * @param ts5 the 5th Future
+
+ * @param the component type of the 1st Future
+ * @param the component type of the 2nd Future
+ * @param the component type of the 3rd Future
+ * @param the component type of the 4th Future
+ * @param the component type of the 5th Future
+ * @return a new {@code ForLazy5Future} builder of arity 5
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy5Future For(Future ts1, Function1 super T1, Future> ts2, Function2 super T1, ? super T2, Future> ts3, Function3 super T1, ? super T2, ? super T3, Future> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Future> ts5) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ return new ForLazy5Future<>(ts1, ts2, ts3, ts4, ts5);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 6 Futures.
+ *
+ * The first argument ({@code ts1}) is the initial Future. Each subsequent
+ * argument ({@code ts2} .. {@code ts6}) is a function that receives all values
+ * bound so far and returns the next Future. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Future
+ * @param ts2 the 2nd Future
+ * @param ts3 the 3rd Future
+ * @param ts4 the 4th Future
+ * @param ts5 the 5th Future
+ * @param ts6 the 6th Future
+
+ * @param the component type of the 1st Future
+ * @param the component type of the 2nd Future
+ * @param the component type of the 3rd Future
+ * @param the component type of the 4th Future
+ * @param the component type of the 5th Future
+ * @param the component type of the 6th Future
+ * @return a new {@code ForLazy6Future} builder of arity 6
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy6Future For(Future ts1, Function1 super T1, Future> ts2, Function2 super T1, ? super T2, Future> ts3, Function3 super T1, ? super T2, ? super T3, Future> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Future> ts5, Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, Future> ts6) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ Objects.requireNonNull(ts6, "ts6 is null");
+ return new ForLazy6Future<>(ts1, ts2, ts3, ts4, ts5, ts6);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 7 Futures.
+ *
+ * The first argument ({@code ts1}) is the initial Future. Each subsequent
+ * argument ({@code ts2} .. {@code ts7}) is a function that receives all values
+ * bound so far and returns the next Future. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Future
+ * @param ts2 the 2nd Future
+ * @param ts3 the 3rd Future
+ * @param ts4 the 4th Future
+ * @param ts5 the 5th Future
+ * @param ts6 the 6th Future
+ * @param ts7 the 7th Future
+
+ * @param the component type of the 1st Future
+ * @param the component type of the 2nd Future
+ * @param the component type of the 3rd Future
+ * @param the component type of the 4th Future
+ * @param the component type of the 5th Future
+ * @param the component type of the 6th Future
+ * @param the component type of the 7th Future
+ * @return a new {@code ForLazy7Future} builder of arity 7
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy7Future For(Future ts1, Function1 super T1, Future> ts2, Function2 super T1, ? super T2, Future> ts3, Function3 super T1, ? super T2, ? super T3, Future> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Future> ts5, Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, Future> ts6, Function6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, Future> ts7) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ Objects.requireNonNull(ts6, "ts6 is null");
+ Objects.requireNonNull(ts7, "ts7 is null");
+ return new ForLazy7Future<>(ts1, ts2, ts3, ts4, ts5, ts6, ts7);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 8 Futures.
+ *
+ * The first argument ({@code ts1}) is the initial Future. Each subsequent
+ * argument ({@code ts2} .. {@code ts8}) is a function that receives all values
+ * bound so far and returns the next Future. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Future
+ * @param ts2 the 2nd Future
+ * @param ts3 the 3rd Future
+ * @param ts4 the 4th Future
+ * @param ts5 the 5th Future
+ * @param ts6 the 6th Future
+ * @param ts7 the 7th Future
+ * @param ts8 the 8th Future
+
+ * @param the component type of the 1st Future
+ * @param the component type of the 2nd Future
+ * @param the component type of the 3rd Future
+ * @param the component type of the 4th Future
+ * @param the component type of the 5th Future
+ * @param the component type of the 6th Future
+ * @param the component type of the 7th Future
+ * @param the component type of the 8th Future
+ * @return a new {@code ForLazy8Future} builder of arity 8
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy8Future For(Future ts1, Function1 super T1, Future> ts2, Function2 super T1, ? super T2, Future> ts3, Function3 super T1, ? super T2, ? super T3, Future> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Future> ts5, Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, Future> ts6, Function6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, Future> ts7, Function7 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, Future> ts8) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ Objects.requireNonNull(ts6, "ts6 is null");
+ Objects.requireNonNull(ts7, "ts7 is null");
+ Objects.requireNonNull(ts8, "ts8 is null");
+ return new ForLazy8Future<>(ts1, ts2, ts3, ts4, ts5, ts6, ts7, ts8);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over two Trys.
+ *
+ * The first argument ({@code ts1}) is the initial Try. Each subsequent
+ * argument ({@code ts2} .. {@code ts2}) is a function that receives all values
+ * bound so far and returns the next Try. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Try
+ * @param ts2 the 2nd Try
+
+ * @param the component type of the 1st Try
+ * @param the component type of the 2nd Try
+ * @return a new {@code ForLazy2Try} builder of arity 2
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy2Try For(Try ts1, Function1 super T1, Try> ts2) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ return new ForLazy2Try<>(ts1, ts2);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over three Trys.
+ *
+ * The first argument ({@code ts1}) is the initial Try. Each subsequent
+ * argument ({@code ts2} .. {@code ts3}) is a function that receives all values
+ * bound so far and returns the next Try. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Try
+ * @param ts2 the 2nd Try
+ * @param ts3 the 3rd Try
+
+ * @param the component type of the 1st Try
+ * @param the component type of the 2nd Try
+ * @param the component type of the 3rd Try
+ * @return a new {@code ForLazy3Try} builder of arity 3
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy3Try For(Try ts1, Function1 super T1, Try> ts2, Function2 super T1, ? super T2, Try> ts3) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ return new ForLazy3Try<>(ts1, ts2, ts3);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 4 Trys.
+ *
+ * The first argument ({@code ts1}) is the initial Try. Each subsequent
+ * argument ({@code ts2} .. {@code ts4}) is a function that receives all values
+ * bound so far and returns the next Try. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Try
+ * @param ts2 the 2nd Try
+ * @param ts3 the 3rd Try
+ * @param ts4 the 4th Try
+
+ * @param the component type of the 1st Try
+ * @param the component type of the 2nd Try
+ * @param the component type of the 3rd Try
+ * @param the component type of the 4th Try
+ * @return a new {@code ForLazy4Try} builder of arity 4
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy4Try For(Try ts1, Function1 super T1, Try> ts2, Function2 super T1, ? super T2, Try> ts3, Function3 super T1, ? super T2, ? super T3, Try> ts4) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ return new ForLazy4Try<>(ts1, ts2, ts3, ts4);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 5 Trys.
+ *
+ * The first argument ({@code ts1}) is the initial Try. Each subsequent
+ * argument ({@code ts2} .. {@code ts5}) is a function that receives all values
+ * bound so far and returns the next Try. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Try
+ * @param ts2 the 2nd Try
+ * @param ts3 the 3rd Try
+ * @param ts4 the 4th Try
+ * @param ts5 the 5th Try
+
+ * @param the component type of the 1st Try
+ * @param the component type of the 2nd Try
+ * @param the component type of the 3rd Try
+ * @param the component type of the 4th Try
+ * @param the component type of the 5th Try
+ * @return a new {@code ForLazy5Try} builder of arity 5
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy5Try For(Try ts1, Function1 super T1, Try> ts2, Function2 super T1, ? super T2, Try> ts3, Function3 super T1, ? super T2, ? super T3, Try> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Try> ts5) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ return new ForLazy5Try<>(ts1, ts2, ts3, ts4, ts5);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 6 Trys.
+ *
+ * The first argument ({@code ts1}) is the initial Try. Each subsequent
+ * argument ({@code ts2} .. {@code ts6}) is a function that receives all values
+ * bound so far and returns the next Try. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Try
+ * @param ts2 the 2nd Try
+ * @param ts3 the 3rd Try
+ * @param ts4 the 4th Try
+ * @param ts5 the 5th Try
+ * @param ts6 the 6th Try
+
+ * @param the component type of the 1st Try
+ * @param the component type of the 2nd Try
+ * @param the component type of the 3rd Try
+ * @param the component type of the 4th Try
+ * @param the component type of the 5th Try
+ * @param the component type of the 6th Try
+ * @return a new {@code ForLazy6Try} builder of arity 6
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy6Try For(Try ts1, Function1 super T1, Try> ts2, Function2 super T1, ? super T2, Try> ts3, Function3 super T1, ? super T2, ? super T3, Try> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Try> ts5, Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, Try> ts6) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ Objects.requireNonNull(ts6, "ts6 is null");
+ return new ForLazy6Try<>(ts1, ts2, ts3, ts4, ts5, ts6);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 7 Trys.
+ *
+ * The first argument ({@code ts1}) is the initial Try. Each subsequent
+ * argument ({@code ts2} .. {@code ts7}) is a function that receives all values
+ * bound so far and returns the next Try. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Try
+ * @param ts2 the 2nd Try
+ * @param ts3 the 3rd Try
+ * @param ts4 the 4th Try
+ * @param ts5 the 5th Try
+ * @param ts6 the 6th Try
+ * @param ts7 the 7th Try
+
+ * @param the component type of the 1st Try
+ * @param the component type of the 2nd Try
+ * @param the component type of the 3rd Try
+ * @param the component type of the 4th Try
+ * @param the component type of the 5th Try
+ * @param the component type of the 6th Try
+ * @param the component type of the 7th Try
+ * @return a new {@code ForLazy7Try} builder of arity 7
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy7Try For(Try ts1, Function1 super T1, Try> ts2, Function2 super T1, ? super T2, Try> ts3, Function3 super T1, ? super T2, ? super T3, Try> ts4, Function4 super T1, ? super T2, ? super T3, ? super T4, Try> ts5, Function5 super T1, ? super T2, ? super T3, ? super T4, ? super T5, Try> ts6, Function6 super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, Try> ts7) {
+ Objects.requireNonNull(ts1, "ts1 is null");
+ Objects.requireNonNull(ts2, "ts2 is null");
+ Objects.requireNonNull(ts3, "ts3 is null");
+ Objects.requireNonNull(ts4, "ts4 is null");
+ Objects.requireNonNull(ts5, "ts5 is null");
+ Objects.requireNonNull(ts6, "ts6 is null");
+ Objects.requireNonNull(ts7, "ts7 is null");
+ return new ForLazy7Try<>(ts1, ts2, ts3, ts4, ts5, ts6, ts7);
+ }
+
+ /**
+ * Creates a lazy {@code For}-comprehension over 8 Trys.
+ *
+ * The first argument ({@code ts1}) is the initial Try. Each subsequent
+ * argument ({@code ts2} .. {@code ts8}) is a function that receives all values
+ * bound so far and returns the next Try. This method only constructs the
+ * lazy comprehension; underlying effects are evaluated when {@code yield(...)}
+ * is invoked.
+ *
+ *
+ * @param ts1 the 1st Try
+ * @param ts2 the 2nd Try
+ * @param ts3 the 3rd Try
+ * @param ts4 the 4th Try
+ * @param ts5 the 5th Try
+ * @param ts6 the 6th Try
+ * @param ts7 the 7th Try
+ * @param ts8 the 8th Try
+
+ * @param the component type of the 1st Try
+ * @param the component type of the 2nd Try
+ * @param the component type of the 3rd Try
+ * @param the component type of the 4th Try
+ * @param the component type of the 5th Try
+ * @param the component type of the 6th Try
+ * @param the component type of the 7th Try
+ * @param the component type of the 8th Try
+ * @return a new {@code ForLazy8Try} builder of arity 8
+ * @throws NullPointerException if any argument is {@code null}
+ */
+ public static ForLazy8Try For(Try ts1, Function1 super T1, Try