Paul King created GROOVY-12205:
----------------------------------
Summary: Complete the functional-interface (fat-free) variants of
Closure-taking DGM methods
Key: GROOVY-12205
URL: https://issues.apache.org/jira/browse/GROOVY-12205
Project: Groovy
Issue Type: Improvement
Reporter: Paul King
GROOVY-12054, GROOVY-12034 and GROOVY-12043 introduced "fat-free" variants of
common DGM methods accepting {{java.util.function}} types ({{Function}},
{{Predicate}}, {{BiFunction}}, ...) alongside the classic {{Closure}}
overloads, so lambdas and functional values obtained from Java APIs can be used
with Groovy's collection methods without wrapping. Coverage is currently
partial, which makes the surface irregular: a user (or an AI coding assistant)
who learns that {{collect}} accepts a {{Function}} will reasonably expect
{{collectMany}} to do the same, and currently gets a {{MissingMethodException}}.
This umbrella issue proposes completing the surface to a predictable rule:
{quote}Every Closure-taking collection/map DGM method has a
functional-interface twin, unless the JDK already provides the
equivalent.{quote}
Methods currently without any functional variant (Closure-overload count in
parens): {{collectMany}} (8), {{sum}} (6), {{takeWhile}} (6), {{dropWhile}}
(6), {{countBy}} (4), {{split}} (5), {{flatten}} (4, the {{flattenUsing}}
forms), {{injectAll}} (4), {{collectingMany}} (1). Partial coverage to round
out: {{inject}} (2 of 9), {{groupBy}} (1 of 6), and the key-extractor forms of
{{min}}/{{max}}.
Deliberate exception to confirm rather than implement:
{{removeAll}}/{{retainAll}}, where JDK {{Collection#removeIf(Predicate)}}
already provides the functional spelling.
The work partitions naturally into a few grouped commits or sub-tasks:
transforming ({{collectMany}}/{{collectingMany}}/{{flatten}}), reducing
({{inject}}/{{sum}}/{{countBy}}/{{groupBy}}/{{min}}/{{max}}), slicing
({{takeWhile}}/{{dropWhile}}/{{split}}), running-fold ({{injectAll}}). Each
addition follows the conventions established by GROOVY-12054: matching generics
wildcards, inline javadoc test blocks, and where useful the
{{BiFunction}}/{{BiPredicate}} + trailing-param variants mirroring
{{Lambdas.curryWith}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)