[jira] [Commented] (GROOVY-10074) DGM: Fix transform generics for collect and similar

2021-05-07 Thread Eric Milles (Jira)


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

Eric Milles commented on GROOVY-10074:
--

Suggestion from the mailing list of using Java's functional interfaces, like 
{{Function}}, instead of {{Closure}} would be another way to go here.

> DGM: Fix transform generics for collect and similar
> ---
>
> Key: GROOVY-10074
> URL: https://issues.apache.org/jira/browse/GROOVY-10074
> Project: Groovy
>  Issue Type: Improvement
>  Components: groovy-jdk
>Reporter: Eric Milles
>Priority: Minor
>
> The {{collect}} DGM is defined like this for {{Iterable}}, arrays, etc.:
> {code:java}
>  List collect(Object self, Closure transform)
>  List collect(S[] self, @ClosureParams(FirstParam.Component.class) 
> Closure transform)
>  List collect(Iterable self, 
> @ClosureParams(FirstParam.FirstGenericType.class) Closure transform)
>  List collect(Iterator self, 
> @ClosureParams(FirstParam.FirstGenericType.class) Closure transform)
> {code}
> and like this for the variants that accept an output collection:
> {code:java}
>  Collection collect(Object self, Collection collector, Closure extends T> transform)
> ...
> {code}
> I think {{Closure}} is better.  It would allow plain {{collect}} 
> to work for this example under STC without requiring {{? extends 
> CharSequence}} on the target or a typecast for "it" or the call expression:
> {code:groovy}
> List list = ['string'].collect { it }
> {code}
> For comparison, Java's {{Stream#map}} function is defined this way:
> {code:java}
>  Stream map(Function mapper)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)


[jira] [Commented] (GROOVY-10074) DGM: Fix transform generics for collect and similar

2021-05-07 Thread Eric Milles (Jira)


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

Eric Milles commented on GROOVY-10074:
--

Since the closure is the only type witness for "T" in the call arguments, I'm 
not sure how easily we could handle this since the target for the return value 
is not considered at the same time.

> DGM: Fix transform generics for collect and similar
> ---
>
> Key: GROOVY-10074
> URL: https://issues.apache.org/jira/browse/GROOVY-10074
> Project: Groovy
>  Issue Type: Improvement
>  Components: groovy-jdk
>Reporter: Eric Milles
>Priority: Minor
>
> The {{collect}} DGM is defined like this for {{Iterable}}, arrays, etc.:
> {code:java}
>  List collect(Object self, Closure transform)
>  List collect(S[] self, @ClosureParams(FirstParam.Component.class) 
> Closure transform)
>  List collect(Iterable self, 
> @ClosureParams(FirstParam.FirstGenericType.class) Closure transform)
>  List collect(Iterator self, 
> @ClosureParams(FirstParam.FirstGenericType.class) Closure transform)
> {code}
> and like this for the variants that accept an output collection:
> {code:java}
>  Collection collect(Object self, Collection collector, Closure extends T> transform)
> ...
> {code}
> I think {{Closure}} is better.  It would allow plain {{collect}} 
> to work for this example under STC without requiring {{? extends 
> CharSequence}} on the target or a typecast for "it" or the call expression:
> {code:groovy}
> List list = ['string'].collect { it }
> {code}
> For comparison, Java's {{Stream#map}} function is defined this way:
> {code:java}
>  Stream map(Function mapper)
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)