This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 8d2f9157dd GROOVY-11602: Add DGM#toTuple(Map.Entry)
8d2f9157dd is described below
commit 8d2f9157ddd2066284a1ef6191ffa02804f88eb4
Author: Paul King <[email protected]>
AuthorDate: Sun Apr 6 09:37:27 2025 +1000
GROOVY-11602: Add DGM#toTuple(Map.Entry)
---
.../codehaus/groovy/runtime/DefaultGroovyMethods.java | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git
a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 772ed755c4..9d26c3dfff 100644
--- a/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -14804,6 +14804,25 @@ public class DefaultGroovyMethods extends
DefaultGroovyMethodsSupport {
return FormatHelper.toString(value);
}
+
//--------------------------------------------------------------------------
+ // toTuple
+
+ /**
+ * Create a Tuple from the key and value of this Map Entry.
+ *
+ * <pre class="groovyTestCase">
+ * assert [a:1, b:2, c:3]*.toTuple().toString() == '[[a, 1], [b, 2], [c,
3]]'
+ * assert [a:1, b:2, c:3].findAll(e -> e.toTuple().sum() != 'b2') == [a:1,
c:3]
+ * </pre>
+ *
+ * @param entry a Map Entry
+ * @return a tuple containing the key and value.
+ * @since 5.0.0
+ */
+ public static <K, V> Tuple2<K, V> toTuple(Map.Entry<K, V> entry) {
+ return new Tuple2<>(entry.getKey(), entry.getValue());
+ }
+
//--------------------------------------------------------------------------
// toUnique