[
https://issues.apache.org/jira/browse/GROOVY-12054?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King updated GROOVY-12054:
-------------------------------
Description:
h2. Overview
This issue continues work from GROOVY-12034 by introducing
{{java.util.function}}-typed overloads to frequently-used higher-order DGM
(Default Groovy Methods). The new overloads let callers pass {{Predicate}},
{{Function}}, {{Consumer}}, {{BiPredicate}}, {{BiFunction}} and related SAM
types directly, without wrapping them in {{Closure}} objects ("fat-free").
They also compose cleanly with the
{{org.apache.groovy.util.Lambdas.curryWith()}}
helpers: every {{...(self, BiPredicate/BiFunction, param)}} overload is
equivalent to the single-argument form fed a right-curried SAM, i.e.
{{list.find(condition, param) == list.find(curryWith(condition, param))}}.
h2. Standard overloads (22)
These mirror the existing {{Closure}}-based methods one-for-one.
h3. Iterating / transforming
* {{each(Iterable, Consumer)}}
* {{eachWithIndex(Iterable, ObjIntConsumer)}}
* {{collect(Iterator, Function)}}
* {{collect(Iterable, Function)}}
* {{collect(Iterable, Collection, Function)}}
* {{collect(Map, BiFunction)}}
* {{collectEntries(Iterable, Function)}}
* {{groupBy(Iterable, Function)}}
* {{inject(Iterable, BinaryOperator)}}
* {{inject(Iterable, initialValue, BiFunction)}}
h3. Searching / filtering
* {{any(Iterable, Predicate)}}
* {{every(Iterable, Predicate)}}
* {{find(Iterable, Predicate)}}
* {{find(Iterator, Predicate)}}
* {{findAll(Iterable, Predicate)}}
* {{findAll(Iterator, Predicate)}}
* {{findAll(Set, Predicate)}}
* {{findAll(Map, BiPredicate)}}
* {{count(Iterable, Predicate)}}
* {{count(Iterator, Predicate)}}
h3. Lazy iterator variants
* {{collecting(Iterator, Function)}}
* {{findingAll(Iterator, Predicate)}}
h2. @Incubating "With"-style variants (10)
Parameterized two-argument forms that fix {{param}} as the second argument,
baking in the {{curryWith}} right-curry. Marked {{@Incubating}}.
* {{collect(Iterable, BiFunction, param)}}
* {{collecting(Iterator, BiFunction, param)}}
* {{find(Iterable, BiPredicate, param)}}
* {{find(Iterator, BiPredicate, param)}}
* {{findAll(Iterable, BiPredicate, param)}}
* {{findAll(Set, BiPredicate, param)}}
* {{findingAll(Iterator, BiPredicate, param)}}
* {{any(Iterable, BiPredicate, param)}}
* {{every(Iterable, BiPredicate, param)}}
* {{count(Iterable, BiPredicate, param)}}
was:
h2. Overview
Continues the "fat-free lambda" work from GROOVY-12034 by adding
{{java.util.function}}\-typed overloads to the most-used higher-order DGM
methods. Pairs with the {{org.apache.groovy.util.Lambdas}} / {{Closures}}
{{curryWith}} helpers landed under GROOVY-12043 — callers can pass
{{Predicate}}/{{Function}}/{{Consumer}} (and the Bi-* / ObjInt-* SAMs where
shape demands) directly without {{Closure}} wrapping, and compose with
{{Lambdas.curryWith(...)}} for the right-curry pattern that motivated
GROOVY-12034.
h2. Scope
Prime candidates for direct use or use in combination with {{curryWith}}:
* {{each(Iterable<T>, Consumer<? super T>)}} -> {{Iterable<T>}}
* {{findAll(Iterable<T>, Predicate<? super T>)}} -> {{List<T>}}
* {{find(Iterable<T>, Predicate<? super T>)}} -> {{T}}
* {{any(Iterable<T>, Predicate<? super T>)}} -> {{boolean}}
* {{every(Iterable<T>, Predicate<? super T>)}} -> {{boolean}}
* {{inject(Iterable<T>, BinaryOperator<T>)}} -> {{T}} (unseeded)
* {{inject(Iterable<E>, U initial, BiFunction<U, ? super E, U>)}} -> {{U}}
(seeded)
* {{collect(Iterable<E>, Function<? super E, ? extends T>)}} -> {{C}}
* {{collect(Iterable<E>, C collector, Function<? super E, ? extends T>)}} ->
{{C}}
* {{groupBy(Iterable<T>, Function<? super T, ? extends K>)}} -> {{Map<K,
List<T>>}}
* {{eachWithIndex(Iterable<T>, ObjIntConsumer<? super T>)}} -> {{Iterable<T>}}
(uses {{ObjIntConsumer}} to avoid per-element {{Integer}} autoboxing)
* {{collectEntries(Iterable<E>, Function<? super E, ? extends Map.Entry<K,
V>>)}} -> {{Map<K, V>}} (single-function form; the two-function form already
exists)
* {{collect(Map<K, V>, BiFunction<? super K, ? super V, ? extends T>)}} ->
{{List<T>}}
* {{findAll(Map<K, V>, BiPredicate<? super K, ? super V>)}} -> {{Map<K, V>}}
* {{collect(Iterator<E>, Function<? super E, ? extends T>)}} -> {{List<T>}}
* {{findAll(Iterator<T>, Predicate<? super T>)}} -> {{List<T>}} — new; the
existing {{Closure}} family has no {{findAll(Iterator, Closure)}}, so this is a
fat-free-only addition for symmetry with {{collect(Iterator, Function)}}
* {{findAll(Set<T>, Predicate<? super T>)}} -> {{Set<T>}} — the one method
where preserving the {{Set}} self-type matters for downstream membership
semantics
Total: 17 new overloads.
Prime candidates for explicit "With" style methods (all @Incubating):
* {{find(Iterable, BiPredicate<? super T, ? super P>, P)}} -> {{T}}
* {{findAll(Iterable, BiPredicate<? super T, ? super P>, P)}} -> {{List}}
* {{findAll(Set, BiPredicate<? super T, ? super P>, P)}} -> {{Set}}
* {{collect(Iterable, BiFunction<? super E, ? super P, ? extends R>, P)}} ->
{{List}}
Total: 4 new overloads.
> A preliminary set of "fat-free" DGM methods
> -------------------------------------------
>
> Key: GROOVY-12054
> URL: https://issues.apache.org/jira/browse/GROOVY-12054
> Project: Groovy
> Issue Type: Sub-task
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
>
> h2. Overview
> This issue continues work from GROOVY-12034 by introducing
> {{java.util.function}}-typed overloads to frequently-used higher-order DGM
> (Default Groovy Methods). The new overloads let callers pass {{Predicate}},
> {{Function}}, {{Consumer}}, {{BiPredicate}}, {{BiFunction}} and related SAM
> types directly, without wrapping them in {{Closure}} objects ("fat-free").
> They also compose cleanly with the
> {{org.apache.groovy.util.Lambdas.curryWith()}}
> helpers: every {{...(self, BiPredicate/BiFunction, param)}} overload is
> equivalent to the single-argument form fed a right-curried SAM, i.e.
> {{list.find(condition, param) == list.find(curryWith(condition, param))}}.
> h2. Standard overloads (22)
> These mirror the existing {{Closure}}-based methods one-for-one.
> h3. Iterating / transforming
> * {{each(Iterable, Consumer)}}
> * {{eachWithIndex(Iterable, ObjIntConsumer)}}
> * {{collect(Iterator, Function)}}
> * {{collect(Iterable, Function)}}
> * {{collect(Iterable, Collection, Function)}}
> * {{collect(Map, BiFunction)}}
> * {{collectEntries(Iterable, Function)}}
> * {{groupBy(Iterable, Function)}}
> * {{inject(Iterable, BinaryOperator)}}
> * {{inject(Iterable, initialValue, BiFunction)}}
> h3. Searching / filtering
> * {{any(Iterable, Predicate)}}
> * {{every(Iterable, Predicate)}}
> * {{find(Iterable, Predicate)}}
> * {{find(Iterator, Predicate)}}
> * {{findAll(Iterable, Predicate)}}
> * {{findAll(Iterator, Predicate)}}
> * {{findAll(Set, Predicate)}}
> * {{findAll(Map, BiPredicate)}}
> * {{count(Iterable, Predicate)}}
> * {{count(Iterator, Predicate)}}
> h3. Lazy iterator variants
> * {{collecting(Iterator, Function)}}
> * {{findingAll(Iterator, Predicate)}}
> h2. @Incubating "With"-style variants (10)
> Parameterized two-argument forms that fix {{param}} as the second argument,
> baking in the {{curryWith}} right-curry. Marked {{@Incubating}}.
> * {{collect(Iterable, BiFunction, param)}}
> * {{collecting(Iterator, BiFunction, param)}}
> * {{find(Iterable, BiPredicate, param)}}
> * {{find(Iterator, BiPredicate, param)}}
> * {{findAll(Iterable, BiPredicate, param)}}
> * {{findAll(Set, BiPredicate, param)}}
> * {{findingAll(Iterator, BiPredicate, param)}}
> * {{any(Iterable, BiPredicate, param)}}
> * {{every(Iterable, BiPredicate, param)}}
> * {{count(Iterable, BiPredicate, param)}}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)