@@ -98,7 +98,8 @@ def generateMainClasses(): Unit = {
98
98
val PredicateType = im.getType(" java.util.function.Predicate" )
99
99
val SupplierType = im.getType(" java.util.function.Supplier" )
100
100
101
- val monadicTypesFor = List (" Iterable" , OptionType , FutureType , TryType , ListType )
101
+ val monadicTypesFor = List (" Iterable" , OptionType , FutureType , TryType , ListType , EitherType , ValidationType )
102
+ val monadicTypesThatNeedParameter = List (EitherType , ValidationType )
102
103
103
104
def genTraversableAliases (traversableType : String , returnType : String , name : String ) = xs """
104
105
// -- $name
@@ -772,12 +773,15 @@ def generateMainClasses(): Unit = {
772
773
773
774
${monadicTypesFor.gen(mtype => (1 to N ).gen(i => {
774
775
val forClassName = if (mtype == " Iterable" ) { s " For $i" } else { s " For $i$mtype" }
775
- val generics = (1 to i).gen(j => s " T $j" )(" , " )
776
- val params = (1 to i).gen(j => s " $mtype<T $j> ts $j" )(" , " )
776
+ val isComplex = monadicTypesThatNeedParameter.contains(mtype)
777
+ val parameterInset = (if (isComplex) {" L, " } else " " )
778
+ val generics = parameterInset + (1 to i).gen(j => s " T $j" )(" , " )
779
+ val params = (1 to i).gen(j => s " $mtype< ${parameterInset}T $j> ts $j" )(" , " )
777
780
xs """
778
781
/ $javadoc
779
782
* Creates a {@code For}-comprehension of ${i.numerus(mtype)}.
780
783
${(0 to i).gen(j => if (j == 0 ) " *" else s " * @param ts $j the ${j.ordinal} $mtype" )(" \n " )}
784
+ ${if (isComplex) s " * @param <L> left-hand type of all ${mtype}s \n " else " " }
781
785
${(1 to i).gen(j => s " * @param <T $j> component type of the ${j.ordinal} $mtype" )(" \n " )}
782
786
* @return a new {@code For}-comprehension of arity $i
783
787
*/
@@ -792,7 +796,8 @@ def generateMainClasses(): Unit = {
792
796
val rtype = if (mtype == " Iterable" ) { IteratorType } else { mtype }
793
797
val cons : String => String = if (mtype == " Iterable" ) { m => s " $IteratorType.ofAll( $m) " } else { m => m }
794
798
val forClassName = if (mtype == " Iterable" ) { s " For $i" } else { s " For $i$mtype" }
795
- val generics = (1 to i).gen(j => s " T $j" )(" , " )
799
+ val parameterInset = (if (monadicTypesThatNeedParameter.contains(mtype)) { " L, " } else " " )
800
+ val generics = parameterInset + (1 to i).gen(j => s " T $j" )(" , " )
796
801
val functionType = i match {
797
802
case 1 => FunctionType
798
803
case 2 => BiFunctionType
@@ -805,20 +810,20 @@ def generateMainClasses(): Unit = {
805
810
*/
806
811
public static class $forClassName< $generics> {
807
812
808
- ${(1 to i).gen(j => xs """ private final $mtype<T $j> ts $j; """ )(" \n " )}
813
+ ${(1 to i).gen(j => xs """ private final $mtype< ${parameterInset} T $j> ts $j; """ )(" \n " )}
809
814
810
- private $forClassName( ${(1 to i).gen(j => s " $mtype<T $j> ts $j" )(" , " )}) {
815
+ private $forClassName( ${(1 to i).gen(j => s " $mtype< ${parameterInset} T $j> ts $j" )(" , " )}) {
811
816
${(1 to i).gen(j => xs """ this.ts $j = ts $j; """ )(" \n " )}
812
817
}
813
818
814
819
/ $javadoc
815
- * Yields a result for elements of the cross product of the underlying ${i.plural(mtype)}.
820
+ * Yields a result for elements of the cross- product of the underlying ${i.plural(mtype)}.
816
821
*
817
- * @param f a function that maps an element of the cross product to a result
822
+ * @param f a function that maps an element of the cross- product to a result
818
823
* @param <R> type of the resulting {@code $rtype} elements
819
824
* @return an {@code $rtype} of mapped results
820
825
*/
821
- public <R> $rtype<R> yield( $functionType< $args, ? extends R> f) {
826
+ public <R> $rtype< ${parameterInset} R> yield( $functionType< $args, ? extends R> f) {
822
827
$Objects.requireNonNull(f, "f is null");
823
828
${if (i == 1 ) xs """
824
829
return ${cons(" ts1" )}.map(f);
@@ -835,7 +840,7 @@ def generateMainClasses(): Unit = {
835
840
*
836
841
* @return an {@code Iterator} of mapped results
837
842
*/
838
- public $rtype<T1> yield() {
843
+ public $rtype< ${parameterInset} T1> yield() {
839
844
return this.yield(Function.identity());
840
845
}
841
846
""" )}
@@ -2657,13 +2662,20 @@ def generateTestClasses(): Unit = {
2657
2662
val SeqType = im.getType(" io.vavr.collection.Seq" )
2658
2663
val MapType = im.getType(" io.vavr.collection.Map" )
2659
2664
val OptionType = im.getType(" io.vavr.control.Option" )
2665
+ val EitherType = im.getType(" io.vavr.control.Either" )
2666
+ val ValidationType = im.getType(" io.vavr.control.Validation" )
2660
2667
val FutureType = im.getType(" io.vavr.concurrent.Future" )
2661
2668
val ExecutorsType = im.getType(" java.util.concurrent.Executors" )
2662
2669
val ExecutorService = s " $ExecutorsType.newSingleThreadExecutor() "
2663
2670
val TryType = im.getType(" io.vavr.control.Try" )
2664
2671
val JavaComparatorType = im.getType(" java.util.Comparator" )
2665
2672
2666
- val monadicTypesFor = List (OptionType )
2673
+ val monadicTypesFor = List (OptionType , EitherType , ValidationType )
2674
+ val monadicTypeMetadataFor = Map (
2675
+ (OptionType -> (" " , " of" )),
2676
+ (EitherType -> (" Object, " , " right" )),
2677
+ (ValidationType -> (" Object, " , " valid" ))
2678
+ )
2667
2679
val monadicFunctionTypesFor = List (FutureType , TryType )
2668
2680
2669
2681
val d = " $"
@@ -2952,11 +2964,14 @@ def generateTestClasses(): Unit = {
2952
2964
}
2953
2965
""" )(" \n\n " )}
2954
2966
2955
- ${monadicTypesFor.gen(mtype => (1 to N ).gen(i => { xs """
2967
+ ${monadicTypesFor.gen(mtype => (1 to N ).gen(i =>
2968
+ val (parameterInset, builderName) = monadicTypeMetadataFor(mtype);
2969
+ { xs """
2970
+
2956
2971
@ $test
2957
2972
public void shouldIterateFor $mtype$i() {
2958
- final $mtype<Integer> result = For(
2959
- ${(1 to i).gen(j => s " $mtype.of ( $j) " )(" ,\n " )}
2973
+ final $mtype< ${parameterInset} Integer> result = For(
2974
+ ${(1 to i).gen(j => s " $mtype. ${builderName} ( $j) " )(" ,\n " )}
2960
2975
).yield( ${(i > 1 ).gen(" (" )}${(1 to i).gen(j => s " i $j" )(" , " )}${(i > 1 ).gen(" )" )} -> ${(1 to i).gen(j => s " i $j" )(" + " )});
2961
2976
$assertThat(result.get()).isEqualTo( ${(1 to i).sum});
2962
2977
}
0 commit comments