[ 
https://issues.apache.org/jira/browse/GROOVY-11606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17942103#comment-17942103
 ] 

Paul King edited comment on GROOVY-11606 at 4/9/25 6:52 AM:
------------------------------------------------------------

A summary of behavior for delegate vs no delegate cases (orthogonal issue to 
"Lazy" naming):
{code}
def toUpperCase() { 'X' }

@groovy.transform.CompileStatic
def method() {
  assert ['a', 'B', 'c'].iterator().collectLazy {
    it.toUpperCase()
  }.join(' ') == 'A B C'
  assert ['a', 'B', 'c'].iterator().map { String s ->
    s.toUpperCase()
  }.join(' ') == 'A B C'
  assert ['a', 'B', 'c'].iterator().collectLazy {
    toUpperCase()
  }.join(' ') == 'X X X'
  assert ['a', 'B', 'c'].iterator().map { String s ->
    toUpperCase()
  }.join(' ') == 'X X X'
  assert ['a', 'B', 'c'].iterator().collectLazy {
    it.toLowerCase()
  }.join(' ') == 'a b c'
  assert ['a', 'B', 'c'].iterator().map { String s ->
    s.toLowerCase()
  }.join(' ') == 'a b c'
  assert ['a', 'B', 'c'].iterator().collectLazy {
    toLowerCase()
  }.join(' ') == 'a b c'
// NOT Possible
//  assert ['a', 'B', 'c'].iterator().map { String s ->
//    toLowerCase()
//  }.join(' ') == 'a b c'
}
{code}
So, it isn't really about breakage since owner first is what I am proposing, 
but there is a performance penalty.


was (Author: paulk):
A summary of behavior for delegate vs no delegate cases (orthogonal issue to 
"Lazy" naming):
{code}
def toUpperCase() { 'X' }

@groovy.transform.CompileStatic
def method() {
  assert ['a', 'B', 'c'].iterator().collectLazy {
    it.toUpperCase()
  }.join(' ') == 'A B C'
  assert ['a', 'B', 'c'].iterator().map { String s ->
    s.toUpperCase()
  }.join(' ') == 'A B C'
  assert ['a', 'B', 'c'].iterator().collectLazy {
    toUpperCase()
  }.join(' ') == 'X X X'
  assert ['a', 'B', 'c'].iterator().map { String s ->
    toUpperCase()
  }.join(' ') == 'X X X'
  assert ['a', 'B', 'c'].iterator().collectLazy {
    it.toLowerCase()
  }.join(' ') == 'a b c'
  assert ['a', 'B', 'c'].iterator().map { String s ->
    s.toLowerCase()
  }.join(' ') == 'a b c'
  assert ['a', 'B', 'c'].iterator().collectLazy {
    toLowerCase()
  }.join(' ') == 'a b c'
// NOT Possible
//  assert ['a', 'B', 'c'].iterator().map { String s ->
//    toLowerCase()
//  }.join(' ') == 'a b c'
}
{code}

> Lazy findAll, collect, collectMany
> ----------------------------------
>
>                 Key: GROOVY-11606
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11606
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>
> See:
> https://lists.apache.org/thread/xv1bpgc7xp3rwp7qt627xfyd10ljcwbc



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

Reply via email to