[
https://issues.apache.org/jira/browse/GROOVY-11596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Paul King closed GROOVY-11596.
------------------------------
> Additional DGM lazy iterator methods
> ------------------------------------
>
> Key: GROOVY-11596
> URL: https://issues.apache.org/jira/browse/GROOVY-11596
> Project: Groovy
> Issue Type: Improvement
> Reporter: Paul King
> Assignee: Paul King
> Priority: Major
> Fix For: 5.0.0-beta-1
>
>
> This issue is to provide a few more iterator variants in the DGM methods.
> Some of these methods already exist but have an eager implementation. Others
> are inspired from [groovy-stream|https://timyates.github.io/groovy-stream/].
> Instead of being executing in multiple seconds, as is, the following code
> executes in a few 10s of ms with the iterator line uncommented, and creates
> much fewer intermediate collections.
> {code:groovy}
> assert (1..10000)
> // .iterator()
> .repeat(10000)
> .take(20000000)
> .takeWhile{ true }
> .drop(5)
> .toUnique()
> .collate(2)
> .flatten{ it * 2 }
> .dropRight(1)
> .dropWhile{ it < 15 }
> .withIndex()
> .init()
> .take(5)
> .injectAll([0, 0]){ a, b -> [a.first() + b.first(), a.last() + b.last()] }
> .collect()
> .toString() == '[[16, 0], [34, 1], [54, 3], [76, 6], [100, 10]]'
> {code}
> In the above example, the existing methods on iterators are: drop, init,
> take, takeWhile, withIndex, dropRight, toUnique
> Existing methods on iterables only: collate, flatten
> Existing eager iterator methods: injectAll
> New methods: repeat (this is an alias for multiply when giving a count but
> matches the groovy-stream name and makes more sense when using the infinite
> count)
> This is continuing Groovy's support for stream-like functionality. You can
> think of all Iterator DGM methods that return iterators as like intermediate
> operators. The methods on Iterator which return other things are like
> collector operators, e.g. collect*, any, average, count, find*, inject, etc.
> Groovy-stream has much further functionality we could look at:
> * faux list comprehension variant of cross-product
> * filter/map/flatMap which we could implement just on iterators and
> effectively provide intermediate variants for findAll/collect/collectMany
--
This message was sent by Atlassian Jira
(v8.20.10#820010)