[ https://issues.apache.org/jira/browse/GROOVY-11586?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Paul King updated GROOVY-11586: ------------------------------- Issue Type: New Feature (was: Improvement) > Provide an injectAll DGM method > ------------------------------- > > Key: GROOVY-11586 > URL: https://issues.apache.org/jira/browse/GROOVY-11586 > Project: Groovy > Issue Type: New Feature > Reporter: Paul King > Assignee: Paul King > Priority: Major > Fix For: 5.0.0-beta-1 > > > 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)