[
https://issues.apache.org/jira/browse/GROOVY-12216?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King resolved GROOVY-12216.
--------------------------------
Fix Version/s: 6.0.0-beta-1
Resolution: Fixed
> Fat-free twins for the fold/reduce DGM methods (inject, injectAll)
> ------------------------------------------------------------------
>
> Key: GROOVY-12216
> URL: https://issues.apache.org/jira/browse/GROOVY-12216
> Project: Groovy
> Issue Type: Sub-task
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
> Fix For: 6.0.0-beta-1
>
>
> h3. Summary
> Sub-task of GROOVY-12205. Adds functional-interface twins for the fold/reduce
> family. Grouped together because they share one design decision — the
> {{BinaryOperator}} vs {{BiFunction}} choice and how it pairs with the
> {{initialValue}} overloads — so the type conventions are settled once.
> {{inject}} on {{Iterable}} already has both twins (from GROOVY-12054); this
> completes the remaining receivers.
> ({{sum}} was originally grouped here but is split out — its twin collides
> positionally with an existing {{Object initialValue}} overload; see the
> separate {{sum}} item.)
> h3. Type convention
> * No-initial-value forms (2-arg reduce): {{BinaryOperator<T>}}.
> * Initial-value forms (3-arg reduce): {{BiFunction<? super U, ? super E, ?
> extends U>}}, matching the existing {{inject(Iterable, U, BiFunction)}}.
> No collision risk: in both methods the reduce function sits in a distinct
> trailing position after any explicit {{initialValue}} parameter, so it never
> competes with the initial value for overload selection.
> h3. Methods
> ||Method||Closure overloads without a twin||Functional type||Receivers||
> |{{inject}}|8|{{BinaryOperator<T>}} (no init) / {{BiFunction<? super U, ?
> super E, ? extends U>}} (init)|no-init: Object, {{E[]}}, Collection;
> with-init: Object, Iterator, Map, {{E[]}}, Collection|
> |{{injectAll}}|5|{{BinaryOperator<T>}} (no init) / {{BiFunction}}
> (init)|no-init: Iterable, Iterator; with-init: Iterable, Iterator, Map|
> Total: 13 new overloads.
> h3. Conventions (per GROOVY-12054)
> * PECS wildcards; {{@since 6.0.0}}; inline javadoc example via {{<pre
> class="language-groovy groovyTestCase">}} cross-linking the {{Closure}}
> counterpart with {{@link}}.
> * Plain single-SAM overloads only — not {{@Incubating}}.
> h3. Compatibility
> * *{{inject}} arity*: since {{BinaryOperator<T> extends BiFunction<T,T,T>}},
> the no-init ({{BinaryOperator}}, 2-arg) and with-init ({{BiFunction}}, 3-arg)
> forms stay distinct by arity — no erasure clash, mirroring the existing
> {{Iterable}} pair.
> * Existing closure/lambda call sites unaffected; method references and typed
> functional values select the twin under {{@CompileStatic}} (GROOVY-12214).
> Only check: an existing {{@CompileStatic}} call passing a literal {{null}} to
> a currently-single-overload form would become ambiguous — grep-checkable,
> resolved with a cast if found.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)