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

Henri Biestro commented on JEXL-269:
------------------------------------

On maps, looping on entries allows explicit access to both the key and the 
value per entry.
 {code:java}
 for(var e : map.entries()) {
      var key = e.key;
      var value = e.value;
.... 
}
{code}
 A list is not necessarily a RandomAccess collection; the so called iteration 
index may only be an iteration counter in the general case. And a counter 
should not be used as a general purpose access index the way a key is used in a 
map. Besides, the casual
{code:java}
var i = 0;
for(var item : list) { i += 1; ... }
{code} seems an understandable pattern to most coders.

 Arguably here again, shortening the syntax does not seem to make the intent 
clearer and may be very misleading in terms of performance.

> Indexed for-loop
> ----------------
>
>                 Key: JEXL-269
>                 URL: https://issues.apache.org/jira/browse/JEXL-269
>             Project: Commons JEXL
>          Issue Type: New Feature
>    Affects Versions: 3.1
>         Environment: I have created a PR for this feature, please see 
> [PR#12|https://github.com/apache/commons-jexl/pull/12]
>            Reporter: Dmitri Blinov
>            Priority: Minor
>
> Introduce new extended syntax of 'for' statement, which allows to specify two 
> variables, like the following
> {code:java}
> for (var i, item : list){code}
> Inside the loop, the first variable gets current iteration index, starting 
> from 0, and the second variable gets current iterated value. The special 
> consideration is taken for iteration over map entries, like the following
> {code:java}
> for(var key, entry : map){code}
> , in this case the first variable is the map key, and the second is the 
> corresponding map value



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to