[ 
https://issues.apache.org/jira/browse/GROOVY-11596?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Paul King updated GROOVY-11596:
-------------------------------
    Description: 
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 multiple when giving a count but 
matches groovy-stream and makes more sense when using the infinite count)


  was:
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)
  .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}


> 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
>
> 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 multiple when giving a count but 
> matches groovy-stream and makes more sense when using the infinite count)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to