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

ASF GitHub Bot commented on GROOVY-10682:
-----------------------------------------

paulk-asert commented on PR #1785:
URL: https://github.com/apache/groovy/pull/1785#issuecomment-1255602797

   We have used code generators (hand-hacked throwaway Groovy scripts) from 
time to time to generate repeated patterns.
   
   We could enhance both the dynamic and static behaviours to do some kind of 
array-level "auto-unboxing" for T[] and the like but we have opted not to in 
the past for better Java integration and (at the time) efficiency with the 
hand-coded primitive variants likely to be more efficient.
   
   We also have `IntArrayIterable` (and Long/Double variants). So we could 
write:
   
   ```
   public static int[] eachWithIndex(int[] self, 
@ClosureParams(value=FromString.class, options="Integer,Integer") Closure 
closure) {
       eachWithIndex(new IntArrayIterable(self), closure);
       return self;
   }
   
   ```
   This saves work when writing the new variants but is probably slightly less 
efficient that the current code in this PR.




> Provide eachWithIndex for primitive arrays
> ------------------------------------------
>
>                 Key: GROOVY-10682
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10682
>             Project: Groovy
>          Issue Type: Improvement
>          Components: groovy-jdk
>            Reporter: Eric Milles
>            Assignee: Eric Milles
>            Priority: Minor
>
> Consider the following:
> {code:groovy}
> @groovy.transform.TypeChecked
> void test(int[] ints) {
>   ints.eachWithIndex { value, index ->
>     println "$index: ${value.doubleValue()}"
>   }
> }
> test(0,1,2,3,4,5)
> {code}
> Compiler reports "[Static type checking] - Cannot find matching method 
> java.lang.Object#doubleValue()"
> {{eachWithIndex}} is only provided for reference types, so "value" is seen as 
> Object by the type checker.



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

Reply via email to