[ https://issues.apache.org/jira/browse/GROOVY-11586?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17938913#comment-17938913 ]
ASF GitHub Bot commented on GROOVY-11586: ----------------------------------------- paulk-asert opened a new pull request, #2166: URL: https://github.com/apache/groovy/pull/2166 (no comment) > Provide an injectAll DGM method > ------------------------------- > > Key: GROOVY-11586 > URL: https://issues.apache.org/jira/browse/GROOVY-11586 > Project: Groovy > Issue Type: Improvement > Reporter: Paul King > Priority: Major > > Streams have both reduce and scan (in gatherers as part of JDK 24). Groovy > has inject for reduce but no equivalent for scan. The intention is to provide > injectAll to provide this: > {code:groovy} > assert (1..3).injectAll(''){ carry, next -> carry + next } == ['1', '12', > '123'] > var runningAvg = [1.0, 2.0, 3.0].injectAll([0.0, 0, null]){ accum, next -> > var total = accum[0] + next > var count = accum[1] + 1 > [total, count, total/count] > } > assert runningAvg*.get(2) == [1.0, 1.5, 2.0] > assert [a:1, b:2, c:3].injectAll('') { carry, k, v -> > carry + k * v > } == ['a', 'abb', 'abbccc'] > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)