feat: Add groupedAdjacentBy and GroupedAdjacentByWeighted operators. (#1937)

This commit is contained in:
He-Pin(kerr) 2025-07-10 10:54:46 +08:00 committed by GitHub
parent c6af89b083
commit ec7fdc7d0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 677 additions and 0 deletions

View file

@ -467,6 +467,32 @@ class SourceOrFlow {
// #groupedWeighted
}
void groupedAdjacentByExample() {
// #groupedAdjacentBy
Source.from(Arrays.asList("Hello", "Hi", "Greetings", "Hey"))
.groupedAdjacentBy(str -> str.charAt(0))
.runForeach(System.out::println, system);
// prints:
// [Hello, Hi]
// [Greetings]
// [Hey]
// #groupedAdjacentBy
}
void groupedAdjacentByWeightedExample() {
// #groupedAdjacentByWeighted
Source.from(Arrays.asList("Hello", "HiHi", "Hi", "Hi", "Greetings", "Hey"))
.groupedAdjacentByWeighted(str -> str.charAt(0), 4, str -> (long) str.length())
.runForeach(System.out::println, system);
// prints:
// [Hello]
// [HiHi]
// [Hi, Hi]
// [Greetings]
// [Hey]
// #groupedAdjacentByWeighted
}
static
// #fold // #foldAsync
class Histogram {