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 f54ba8d  draft gatherers4j blog post (minor tweaks)
f54ba8d is described below

commit f54ba8dd264c274eb8258a24227db3b169a8e6bb
Author: Paul King <[email protected]>
AuthorDate: Thu Apr 10 23:41:22 2025 +1000

    draft gatherers4j blog post (minor tweaks)
---
 site/src/site/blog/exploring-gatherers4j.adoc | 31 ++++++++++++---------------
 1 file changed, 14 insertions(+), 17 deletions(-)

diff --git a/site/src/site/blog/exploring-gatherers4j.adoc 
b/site/src/site/blog/exploring-gatherers4j.adoc
index 93be92d..63c1b86 100644
--- a/site/src/site/blog/exploring-gatherers4j.adoc
+++ b/site/src/site/blog/exploring-gatherers4j.adoc
@@ -617,7 +617,7 @@ Groovy provides `zip`:
 {start-blue}
 assert abc.iterator()
     .zip(nums.iterator())
-    .collectLazy{ s, n -> s + n }
+    .collectLazy { s, n -> s + n }
     .toList() == ['A1', 'B2', 'C3']
 {end}
 ----
@@ -627,12 +627,17 @@ Groovy-stream, offers the same:
 [source,groovy,subs="+macros,+attributes"]
 ----
 {start-orange}
-assert Stream.from(abc).zip(nums){ s, i -> s + i }.toList() == ['A1', 'B2', 
'C3']
+assert Stream.from(abc)
+    .zip(nums) { s, i -> s + i }
+    .toList() == ['A1', 'B2', 'C3']
 {end}
 ----
 
 === distinctBy, toUnique
 
+Gatherers4j has a `distinctBy` gatherer that finds unique elements
+using a predicate to determine equality:
+
 [source,groovy,subs="+macros,+attributes"]
 ----
 {start-green}
@@ -642,29 +647,21 @@ assert Stream.of('A', 'BB', 'CC', 'D')
 {end}
 ----
 
-[source,groovy,subs="+macros,+attributes"]
-----
-{start-blue}
-int idx = abc.size()
-assert Stream.generate {
-    idx %= abc.size()
-    abc[idx++]
-}
-.limit(5)
-.toList() == ['A', 'B', 'C', 'A', 'B']
-{end}
-----
+Groovy provides `toUnique` for this:
 
 [source,groovy,subs="+macros,+attributes"]
 ----
-{start-orange}
-assert Stream.from(abc).repeat().take(5).toList()
-  == ['A', 'B', 'C', 'A', 'B']
+{start-blue}
+assert ['A', 'BB', 'CC', 'D'].iterator()
+    .toUnique(String::size)
+    .toList() == ['A', 'BB']
 {end}
 ----
 
 === dropEveryNth/takeEveryNth
 
+Gatherers4j has special gatherers to take or drop every nth element:
+
 [source,groovy,subs="+macros,+attributes"]
 ----
 {start-green}

Reply via email to