You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2018/11/26 14:34:37 UTC

groovy git commit: Add missing concat methods of tuples

Repository: groovy
Updated Branches:
  refs/heads/master aa372c484 -> b6933c7ef


Add missing concat methods of tuples


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/b6933c7e
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b6933c7e
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b6933c7e

Branch: refs/heads/master
Commit: b6933c7ef628a199d5960b6ab96c61fca3fe7302
Parents: aa372c4
Author: Daniel Sun <su...@apache.org>
Authored: Mon Nov 26 22:34:10 2018 +0800
Committer: Daniel Sun <su...@apache.org>
Committed: Mon Nov 26 22:34:10 2018 +0800

----------------------------------------------------------------------
 src/main/groovy/groovy/lang/Tuple0.java  |  7 +++++
 src/main/groovy/groovy/lang/Tuple1.java  |  7 +++++
 src/main/groovy/groovy/lang/Tuple10.java |  7 +++++
 src/main/groovy/groovy/lang/Tuple11.java |  7 +++++
 src/main/groovy/groovy/lang/Tuple12.java |  7 +++++
 src/main/groovy/groovy/lang/Tuple13.java |  8 ++++++
 src/main/groovy/groovy/lang/Tuple14.java |  7 +++++
 src/main/groovy/groovy/lang/Tuple15.java |  7 +++++
 src/main/groovy/groovy/lang/Tuple16.java |  3 +++
 src/main/groovy/groovy/lang/Tuple2.java  |  7 +++++
 src/main/groovy/groovy/lang/Tuple3.java  |  8 ++++++
 src/main/groovy/groovy/lang/Tuple4.java  |  8 ++++++
 src/main/groovy/groovy/lang/Tuple5.java  |  7 +++++
 src/main/groovy/groovy/lang/Tuple6.java  |  8 ++++++
 src/main/groovy/groovy/lang/Tuple7.java  |  8 ++++++
 src/main/groovy/groovy/lang/Tuple8.java  |  8 ++++++
 src/main/groovy/groovy/lang/Tuple9.java  |  8 ++++++
 src/test/groovy/lang/TupleTest.java      | 38 ++++++++++++++++++++++++++-
 18 files changed, 159 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple0.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple0.java b/src/main/groovy/groovy/lang/Tuple0.java
index f46c8f9..c7c4d9c 100644
--- a/src/main/groovy/groovy/lang/Tuple0.java
+++ b/src/main/groovy/groovy/lang/Tuple0.java
@@ -41,6 +41,13 @@ public final class Tuple0 extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple0 concat(Tuple0 tuple) {
+        return INSTANCE;
+    }
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T1> Tuple1<T1> concat(Tuple1<T1> tuple) {
         return new Tuple1<>(tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple1.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple1.java b/src/main/groovy/groovy/lang/Tuple1.java
index 9ecc6d0..bef131c 100644
--- a/src/main/groovy/groovy/lang/Tuple1.java
+++ b/src/main/groovy/groovy/lang/Tuple1.java
@@ -58,6 +58,13 @@ public final class Tuple1<T1> extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple1<T1> concat(Tuple0 tuple) {
+        return new Tuple1<>(v1);
+    }
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T2> Tuple2<T1, T2> concat(Tuple1<T2> tuple) {
         return new Tuple2<>(v1, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple10.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple10.java b/src/main/groovy/groovy/lang/Tuple10.java
index 55ee715..97b6408 100644
--- a/src/main/groovy/groovy/lang/Tuple10.java
+++ b/src/main/groovy/groovy/lang/Tuple10.java
@@ -111,6 +111,13 @@ public final class Tuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> extends Tupl
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> concat(Tuple0 tuple) {
+        return new Tuple10<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10);
+    }
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T11> Tuple11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> concat(Tuple1<T11> tuple) {
         return new Tuple11<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple11.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple11.java b/src/main/groovy/groovy/lang/Tuple11.java
index 96baab0..04c4133 100644
--- a/src/main/groovy/groovy/lang/Tuple11.java
+++ b/src/main/groovy/groovy/lang/Tuple11.java
@@ -117,6 +117,13 @@ public final class Tuple11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> extends
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple11<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> concat(Tuple0 tuple) {
+        return new Tuple11<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11);
+    }
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T12> Tuple12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> concat(Tuple1<T12> tuple) {
         return new Tuple12<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple12.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple12.java b/src/main/groovy/groovy/lang/Tuple12.java
index 7eee60e..b0d83bb 100644
--- a/src/main/groovy/groovy/lang/Tuple12.java
+++ b/src/main/groovy/groovy/lang/Tuple12.java
@@ -124,6 +124,13 @@ public final class Tuple12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> ex
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple12<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> concat(Tuple0 tuple) {
+        return new Tuple12<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12);
+    }
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T13> Tuple13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> concat(Tuple1<T13> tuple) {
         return new Tuple13<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple13.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple13.java b/src/main/groovy/groovy/lang/Tuple13.java
index 70a5189..2a240d5 100644
--- a/src/main/groovy/groovy/lang/Tuple13.java
+++ b/src/main/groovy/groovy/lang/Tuple13.java
@@ -129,6 +129,14 @@ public final class Tuple13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T1
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple13<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> concat(Tuple0 tuple) {
+        return new Tuple13<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13);
+    }
+
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T14> Tuple14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> concat(Tuple1<T14> tuple) {
         return new Tuple14<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple14.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple14.java b/src/main/groovy/groovy/lang/Tuple14.java
index a7c9db1..934af52 100644
--- a/src/main/groovy/groovy/lang/Tuple14.java
+++ b/src/main/groovy/groovy/lang/Tuple14.java
@@ -134,6 +134,13 @@ public final class Tuple14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T1
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple14<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> concat(Tuple0 tuple) {
+        return new Tuple14<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14);
+    }
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T15> Tuple15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> concat(Tuple1<T15> tuple) {
         return new Tuple15<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple15.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple15.java b/src/main/groovy/groovy/lang/Tuple15.java
index 1c3c67b..b995753 100644
--- a/src/main/groovy/groovy/lang/Tuple15.java
+++ b/src/main/groovy/groovy/lang/Tuple15.java
@@ -140,6 +140,13 @@ public final class Tuple15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T1
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple15<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> concat(Tuple0 tuple) {
+        return new Tuple15<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15);
+    }
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T16> Tuple16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> concat(Tuple1<T16> tuple) {
         return new Tuple16<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple16.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple16.java b/src/main/groovy/groovy/lang/Tuple16.java
index e5532fa..bcc8cc8 100644
--- a/src/main/groovy/groovy/lang/Tuple16.java
+++ b/src/main/groovy/groovy/lang/Tuple16.java
@@ -136,6 +136,9 @@ public final class Tuple16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T1
         return v16;
     }
 
+    public final Tuple16<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> concat(Tuple0 tuple) {
+        return new Tuple16<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16);
+    }
 
     /**
      * Split this tuple into two tuples of degree 0 and 16.

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple2.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple2.java b/src/main/groovy/groovy/lang/Tuple2.java
index baeec81..3e48afc 100644
--- a/src/main/groovy/groovy/lang/Tuple2.java
+++ b/src/main/groovy/groovy/lang/Tuple2.java
@@ -71,6 +71,13 @@ public final class Tuple2<T1, T2> extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple2<T1, T2> concat(Tuple0 tuple) {
+        return new Tuple2<>(v1, v2);
+    }
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T3> Tuple3<T1, T2, T3> concat(Tuple1<T3> tuple) {
         return new Tuple3<>(v1, v2, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple3.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple3.java b/src/main/groovy/groovy/lang/Tuple3.java
index e7b1ead..6ce9b65 100644
--- a/src/main/groovy/groovy/lang/Tuple3.java
+++ b/src/main/groovy/groovy/lang/Tuple3.java
@@ -82,6 +82,14 @@ public final class Tuple3<T1, T2, T3> extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple3<T1, T2, T3> concat(Tuple0 tuple) {
+        return new Tuple3<>(v1, v2, v3);
+    }
+
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T4> Tuple4<T1, T2, T3, T4> concat(Tuple1<T4> tuple) {
         return new Tuple4<>(v1, v2, v3, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple4.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple4.java b/src/main/groovy/groovy/lang/Tuple4.java
index 0ac5245..ce26f00 100644
--- a/src/main/groovy/groovy/lang/Tuple4.java
+++ b/src/main/groovy/groovy/lang/Tuple4.java
@@ -94,6 +94,14 @@ public final class Tuple4<T1, T2, T3, T4> extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple4<T1, T2, T3, T4> concat(Tuple0 tuple) {
+        return new Tuple4<>(v1, v2, v3, v4);
+    }
+
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T5> Tuple5<T1, T2, T3, T4, T5> concat(Tuple1<T5> tuple) {
         return new Tuple5<>(v1, v2, v3, v4, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple5.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple5.java b/src/main/groovy/groovy/lang/Tuple5.java
index e7c4f43..74067bd 100644
--- a/src/main/groovy/groovy/lang/Tuple5.java
+++ b/src/main/groovy/groovy/lang/Tuple5.java
@@ -105,6 +105,13 @@ public final class Tuple5<T1, T2, T3, T4, T5> extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple5<T1, T2, T3, T4, T5> concat(Tuple0 tuple) {
+        return new Tuple5<>(v1, v2, v3, v4, v5);
+    }
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T6> Tuple6<T1, T2, T3, T4, T5, T6> concat(Tuple1<T6> tuple) {
         return new Tuple6<>(v1, v2, v3, v4, v5, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple6.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple6.java b/src/main/groovy/groovy/lang/Tuple6.java
index 8c5620f..14542d4 100644
--- a/src/main/groovy/groovy/lang/Tuple6.java
+++ b/src/main/groovy/groovy/lang/Tuple6.java
@@ -116,6 +116,14 @@ public final class Tuple6<T1, T2, T3, T4, T5, T6> extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple6<T1, T2, T3, T4, T5, T6> concat(Tuple0 tuple) {
+        return new Tuple6<>(v1, v2, v3, v4, v5, v6);
+    }
+
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T7> Tuple7<T1, T2, T3, T4, T5, T6, T7> concat(Tuple1<T7> tuple) {
         return new Tuple7<>(v1, v2, v3, v4, v5, v6, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple7.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple7.java b/src/main/groovy/groovy/lang/Tuple7.java
index e865388..ea06599 100644
--- a/src/main/groovy/groovy/lang/Tuple7.java
+++ b/src/main/groovy/groovy/lang/Tuple7.java
@@ -127,6 +127,14 @@ public final class Tuple7<T1, T2, T3, T4, T5, T6, T7> extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple7<T1, T2, T3, T4, T5, T6, T7> concat(Tuple0 tuple) {
+        return new Tuple7<>(v1, v2, v3, v4, v5, v6, v7);
+    }
+
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T8> Tuple8<T1, T2, T3, T4, T5, T6, T7, T8> concat(Tuple1<T8> tuple) {
         return new Tuple8<>(v1, v2, v3, v4, v5, v6, v7, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple8.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple8.java b/src/main/groovy/groovy/lang/Tuple8.java
index a1e8a03..35a148e 100644
--- a/src/main/groovy/groovy/lang/Tuple8.java
+++ b/src/main/groovy/groovy/lang/Tuple8.java
@@ -138,6 +138,14 @@ public final class Tuple8<T1, T2, T3, T4, T5, T6, T7, T8> extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple8<T1, T2, T3, T4, T5, T6, T7, T8> concat(Tuple0 tuple) {
+        return new Tuple8<>(v1, v2, v3, v4, v5, v6, v7, v8);
+    }
+
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T9> Tuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9> concat(Tuple1<T9> tuple) {
         return new Tuple9<>(v1, v2, v3, v4, v5, v6, v7, v8, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/main/groovy/groovy/lang/Tuple9.java
----------------------------------------------------------------------
diff --git a/src/main/groovy/groovy/lang/Tuple9.java b/src/main/groovy/groovy/lang/Tuple9.java
index ab8b39b..247c845 100644
--- a/src/main/groovy/groovy/lang/Tuple9.java
+++ b/src/main/groovy/groovy/lang/Tuple9.java
@@ -150,6 +150,14 @@ public final class Tuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9> extends Tuple {
     /**
      * Concatenate a tuple to this tuple.
      */
+    public final Tuple9<T1, T2, T3, T4, T5, T6, T7, T8, T9> concat(Tuple0 tuple) {
+        return new Tuple9<>(v1, v2, v3, v4, v5, v6, v7, v8, v9);
+    }
+
+
+    /**
+     * Concatenate a tuple to this tuple.
+     */
     public final <T10> Tuple10<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> concat(Tuple1<T10> tuple) {
         return new Tuple10<>(v1, v2, v3, v4, v5, v6, v7, v8, v9, tuple.getV1());
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/b6933c7e/src/test/groovy/lang/TupleTest.java
----------------------------------------------------------------------
diff --git a/src/test/groovy/lang/TupleTest.java b/src/test/groovy/lang/TupleTest.java
index 8569adb..7fa373e 100644
--- a/src/test/groovy/lang/TupleTest.java
+++ b/src/test/groovy/lang/TupleTest.java
@@ -381,9 +381,45 @@ public class TupleTest extends GroovyTestCase {
         assertEquals(tuple(1, "a", 2, "b", 3, "c", 4, "d", 5, "e", 6, "f", 7, "g", 8), tuple(1).concat("a").concat(2).concat("b").concat(3).concat("c").concat(4).concat("d").concat(5).concat("e").concat(6).concat("f").concat(7).concat("g").concat(8));
         assertEquals(tuple(1, "a", 2, "b", 3, "c", 4, "d", 5, "e", 6, "f", 7, "g", 8, "h"), tuple(1).concat("a").concat(2).concat("b").concat(3).concat("c").concat(4).concat("d").concat(5).concat("e").concat(6).concat("f").concat(7).concat("g").concat(8).concat("h"));
 
-
         assertEquals(tuple(1, "a"), tuple(1).concat(tuple("a")));
         assertEquals(tuple(1, "a", 2, "b", 3, "c", 4, "d"), tuple(1).concat(tuple("a", 2, "b").concat(tuple(3).concat(tuple("c", 4, "d")))));
+
+        assertEquals(new Integer(136), tuple().concat(tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1).concat(tuple(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2).concat(tuple(3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3).concat(tuple(4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4).concat(tuple(5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5).concat(tuple(6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6).concat(tuple(7, 8, 9, 10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7).concat(tuple(8, 9, 10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7, 8).concat(tuple(9, 10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9).concat(tuple(10, 11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).concat(tuple(11, 12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).concat(tuple(12, 13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).concat(tuple(13, 14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).concat(tuple(14, 15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).concat(tuple(15, 16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).concat(tuple(16)).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+        assertEquals(new Integer(136), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16).concat(tuple()).map((v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) -> v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12 + v13 + v14 + v15 + v16));
+
+        assertEquals(tuple(), tuple().concat(tuple()));
+        assertEquals(tuple(1), tuple(1).concat(tuple()));
+        assertEquals(tuple(1, 2), tuple(1, 2).concat(tuple()));
+        assertEquals(tuple(1, 2, 3), tuple(1, 2, 3).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4), tuple(1, 2, 3, 4).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5), tuple(1, 2, 3, 4, 5).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6), tuple(1, 2, 3, 4, 5, 6).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7), tuple(1, 2, 3, 4, 5, 6, 7).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7, 8), tuple(1, 2, 3, 4, 5, 6, 7, 8).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7, 8, 9), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15).concat(tuple()));
+        assertEquals(tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16), tuple(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16).concat(tuple()));
+
     }
 
     public void testCompareTo() {


Re: groovy git commit: Add missing concat methods of tuples

Posted by Daniel Sun <re...@hotmail.com>.
At first tuples should be immutable for better functional programming IMO.

If the operation on tuple does not affact its status, it's OK to return
`this`, i.e. the original tuple(as Paul mentioned)

Cheers,
Daniel.Sun




--
Sent from: http://groovy.329449.n5.nabble.com/Groovy-Dev-f372993.html

Re: groovy git commit: Add missing concat methods of tuples

Posted by MG <mg...@arscreat.com>.
You are right, but I still think it would be a good idea to consider 
introducing a general method naming convention, whatever is decided for 
Tuple (going all immutable or not).

Since frameworks/languages are moving towards more immutability, the 
convention could of course favor that case, e.g.:

Tuple#concat(...) ... create new instance

Tuple#concatThis(...) ... modify instance
Tuple#concatToThis(...) ... modify instance
Tuple#concatIt(...) ... modify instance

Cheers,
mg


Am 26.11.2018 um 21:19 schrieb Mario Garcia:
> Apparently the actual Tuple implementation in main branch is creating 
> new tuples when doing tuple.concat(tuple) (not all but most of), so I 
> guess is just a matter of making sure what a Tuple is in Groovy. Two 
> options:
>
>   * (1) A tuple is a fixed-length container that can hold any values,
>     but cannot be modified (it is immutable) (Taken from Julia Lang)
>   * (2) A tuple is a list of N typed objects (Taken from Groovydoc)
>
> If (1) it doesn't matter the method name because it's clear to me by 
> its definition that a Tuple is always immutable no matter the method 
> called.
> If (2) a list in Groovy can be modified, so, maybe method names are 
> important as MG is mentioning
>
> Once said that, I prefer the immutable version of tuples as value 
> containers, and I'd vote for changing the Groovydoc definition and 
> enforce immutability to avoid ambiguity.
> Mario
>
> El lun., 26 nov. 2018 a las 20:41, MG (<mgbiz@arscreat.com 
> <ma...@arscreat.com>>) escribió:
>
>     My 2 Cents: I supply two seperate methods in that case, e.g.:
>
>     1) Columns#sort(...) ... sort the List<Column> collection held by
>     the Columns class (same name for zero parameters case)
>
>     2a) Columns#getSorted() ... create new Columns instance with its
>     List<Column> sorted
>     2b) Columns#sorted(...) ... create new Columns instance with its
>     List<Column> sorted (parameter case)
>
>     Method names should clearly express what the method does (to me
>     the imperative "sort", compared  with the adjective state "(return
>     something which is) sorted" does that) - nothing worse than you
>     thinking you get a new instance, and end up modifying the original
>     instance, or thinking you are working in place, when in fact you
>     are creating new objects all the time...
>
>     Here:
>
>     Tuple#concat(Tuple)  ... modify existing
>     Tuple#concatenated(Tuple) ... return new instance
>
>     Cheers,
>     mg
>
>
>     Am 26.11.2018 um 19:29 schrieb Mario Garcia:
>>     I'd do it if the intention is to enforce immutability of tuples,
>>     like "...any operation applied to a tuple should result in a new
>>     tuple"
>>
>>     Regards
>>     Mario
>>
>>     El lun., 26 nov. 2018 15:44, Paul King <paul.king.asert@gmail.com
>>     <ma...@gmail.com>> escribió:
>>
>>         On Tue, Nov 27, 2018 at 12:34 AM <sunlan@apache.org
>>         <ma...@apache.org>> wrote:
>>         >
>>         > Repository: groovy
>>         > Updated Branches:
>>         >   refs/heads/master aa372c484 -> b6933c7ef
>>         >
>>         >
>>         > Add missing concat methods of tuples
>>         [SNIP]
>>         >      /**
>>         >       * Concatenate a tuple to this tuple.
>>         >       */
>>         > +    public final Tuple1<T1> concat(Tuple0 tuple) {
>>         > +        return new Tuple1<>(v1);
>>         > +    }
>>         [SNIP]
>>
>>         Returning a new tuple is important? Vs returning this?
>>
>>         Cheers, Paul.
>>
>


Re: groovy git commit: Add missing concat methods of tuples

Posted by Mario Garcia <ma...@gmail.com>.
Apparently the actual Tuple implementation in main branch is creating new
tuples when doing tuple.concat(tuple) (not all but most of), so I guess is
just a matter of making sure what a Tuple is in Groovy. Two options:

   - (1) A tuple is a fixed-length container that can hold any values, but
   cannot be modified (it is immutable) (Taken from Julia Lang)
   - (2) A tuple is a list of N typed objects (Taken from Groovydoc)

If (1) it doesn't matter the method name because it's clear to me by its
definition that a Tuple is always immutable no matter the method called.
If (2) a list in Groovy can be modified, so, maybe method names are
important as MG is mentioning

Once said that, I prefer the immutable version of tuples as value
containers, and I'd vote for changing the Groovydoc definition and enforce
immutability to avoid ambiguity.
Mario

El lun., 26 nov. 2018 a las 20:41, MG (<mg...@arscreat.com>) escribió:

> My 2 Cents: I supply two seperate methods in that case, e.g.:
>
> 1) Columns#sort(...) ... sort the List<Column> collection held by the
> Columns class (same name for zero parameters case)
>
> 2a) Columns#getSorted() ... create new Columns instance with its
> List<Column> sorted
> 2b) Columns#sorted(...) ... create new Columns instance with its
> List<Column> sorted (parameter case)
>
> Method names should clearly express what the method does (to me the
> imperative "sort", compared  with the adjective state "(return something
> which is) sorted" does that) - nothing worse than you thinking you get a
> new instance, and end up modifying the original instance, or thinking you
> are working in place, when in fact you are creating new objects all the
> time...
>
> Here:
>
> Tuple#concat(Tuple)  ... modify existing
> Tuple#concatenated(Tuple) ... return new instance
>
> Cheers,
> mg
>
>
> Am 26.11.2018 um 19:29 schrieb Mario Garcia:
>
> I'd do it if the intention is to enforce immutability of tuples, like
> "...any operation applied to a tuple should result in a new tuple"
>
> Regards
> Mario
>
> El lun., 26 nov. 2018 15:44, Paul King <pa...@gmail.com>
> escribió:
>
>> On Tue, Nov 27, 2018 at 12:34 AM <su...@apache.org> wrote:
>> >
>> > Repository: groovy
>> > Updated Branches:
>> >   refs/heads/master aa372c484 -> b6933c7ef
>> >
>> >
>> > Add missing concat methods of tuples
>> [SNIP]
>> >      /**
>> >       * Concatenate a tuple to this tuple.
>> >       */
>> > +    public final Tuple1<T1> concat(Tuple0 tuple) {
>> > +        return new Tuple1<>(v1);
>> > +    }
>> [SNIP]
>>
>> Returning a new tuple is important? Vs returning this?
>>
>> Cheers, Paul.
>>
>
>

Re: groovy git commit: Add missing concat methods of tuples

Posted by MG <mg...@arscreat.com>.
My 2 Cents: I supply two seperate methods in that case, e.g.:

1) Columns#sort(...) ... sort the List<Column> collection held by the 
Columns class (same name for zero parameters case)

2a) Columns#getSorted() ... create new Columns instance with its 
List<Column> sorted
2b) Columns#sorted(...) ... create new Columns instance with its 
List<Column> sorted (parameter case)

Method names should clearly express what the method does (to me the 
imperative "sort", compared  with the adjective state "(return something 
which is) sorted" does that) - nothing worse than you thinking you get a 
new instance, and end up modifying the original instance, or thinking 
you are working in place, when in fact you are creating new objects all 
the time...

Here:

Tuple#concat(Tuple)  ... modify existing
Tuple#concatenated(Tuple) ... return new instance

Cheers,
mg


Am 26.11.2018 um 19:29 schrieb Mario Garcia:
> I'd do it if the intention is to enforce immutability of tuples, like 
> "...any operation applied to a tuple should result in a new tuple"
>
> Regards
> Mario
>
> El lun., 26 nov. 2018 15:44, Paul King <paul.king.asert@gmail.com 
> <ma...@gmail.com>> escribió:
>
>     On Tue, Nov 27, 2018 at 12:34 AM <sunlan@apache.org
>     <ma...@apache.org>> wrote:
>     >
>     > Repository: groovy
>     > Updated Branches:
>     >   refs/heads/master aa372c484 -> b6933c7ef
>     >
>     >
>     > Add missing concat methods of tuples
>     [SNIP]
>     >      /**
>     >       * Concatenate a tuple to this tuple.
>     >       */
>     > +    public final Tuple1<T1> concat(Tuple0 tuple) {
>     > +        return new Tuple1<>(v1);
>     > +    }
>     [SNIP]
>
>     Returning a new tuple is important? Vs returning this?
>
>     Cheers, Paul.
>


Re: groovy git commit: Add missing concat methods of tuples

Posted by Mario Garcia <ma...@gmail.com>.
I'd do it if the intention is to enforce immutability of tuples, like
"...any operation applied to a tuple should result in a new tuple"

Regards
Mario

El lun., 26 nov. 2018 15:44, Paul King <pa...@gmail.com> escribió:

> On Tue, Nov 27, 2018 at 12:34 AM <su...@apache.org> wrote:
> >
> > Repository: groovy
> > Updated Branches:
> >   refs/heads/master aa372c484 -> b6933c7ef
> >
> >
> > Add missing concat methods of tuples
> [SNIP]
> >      /**
> >       * Concatenate a tuple to this tuple.
> >       */
> > +    public final Tuple1<T1> concat(Tuple0 tuple) {
> > +        return new Tuple1<>(v1);
> > +    }
> [SNIP]
>
> Returning a new tuple is important? Vs returning this?
>
> Cheers, Paul.
>

Re: groovy git commit: Add missing concat methods of tuples

Posted by Paul King <pa...@gmail.com>.
On Tue, Nov 27, 2018 at 12:34 AM <su...@apache.org> wrote:
>
> Repository: groovy
> Updated Branches:
>   refs/heads/master aa372c484 -> b6933c7ef
>
>
> Add missing concat methods of tuples
[SNIP]
>      /**
>       * Concatenate a tuple to this tuple.
>       */
> +    public final Tuple1<T1> concat(Tuple0 tuple) {
> +        return new Tuple1<>(v1);
> +    }
[SNIP]

Returning a new tuple is important? Vs returning this?

Cheers, Paul.