This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/groovy-website.git
The following commit(s) were added to refs/heads/asf-site by this push:
new b00e965 add groupByMany blog post (add stream example)
b00e965 is described below
commit b00e9652f35f71525115452e10c37eb760d28241
Author: Paul King <[email protected]>
AuthorDate: Tue Dec 2 12:38:18 2025 +1000
add groupByMany blog post (add stream example)
---
site/src/site/blog/fruity-eclipse-grouping.adoc | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/site/src/site/blog/fruity-eclipse-grouping.adoc
b/site/src/site/blog/fruity-eclipse-grouping.adoc
index 6de94a8..87449c0 100644
--- a/site/src/site/blog/fruity-eclipse-grouping.adoc
+++ b/site/src/site/blog/fruity-eclipse-grouping.adoc
@@ -126,12 +126,31 @@ assert expected == Fruit.values()
This works well but isn't necessarily obvious at first glance.
+We can also use streams. The JDK21 `mapMulti` stream method
+comes in handy:
+
+[source,groovy]
+----
+assert expected == Fruit.values().stream()
+ .mapMulti((fruit, consumer) -> {
+ for (Color color : fruit.colors) {
+ consumer.accept(Map.entry(color, fruit))
+ }
+ })
+ .collect(Collectors.groupingBy(
+ Map.Entry::getKey,
+ Collectors.mapping(Map.Entry::getValue, Collectors.toList())
+ ))
+----
+
+This also works well, but again isn't necessarily obvious at first glance.
+
== Grouping JDK Collections Fruit Salad with GQuery
Dealing with many-to-many relationships is very common in database systems.
Query languages like SQL have special support for querying such relationships.
It should come as no surprise then, that Groovy's integrated query technology,
-GQuery (groovy-ginq), would also support such relationships.
+GQuery (AKA groovy-ginq), would also support such relationships.
Here is the same example again using GQuery: