Groovy
  1. Groovy
  2. GROOVY-3797

Provide an index or counter for each/find/findAll/collect and friends by taking into accounts the arity of closures passed to them

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: groovy-jdk
    • Labels:
      None

      Description

      As per the suggestion on this thread:
      http://www.nabble.com/generic-%27withIndex%27-method-%28like-Ruby-1.9-with_index%29-ts25631548.html

      The idea is to have access to an index or counter in all the functional methods iterating over collections, by using an additional parameter in the closure passed in parameter of those methods. That way, we don't need to add as many *withIndex variant methods to the existing ones, but rather provide a convenient convention.

      Some examples with each, and similarly by replacing each with find/findAll/any/every/collect and perhaps inject:

      list.each { elem -> ... }
      list.each { elem, counter -> ... }
      
      map.each { entry -> ... }
      map.each { key, value -> ... }
      map.each { key, value, counter -> ... }
      

        Issue Links

          Activity

          Mark Thomas made changes -
          Workflow jira [ 12970525 ] Default workflow, editable Closed status [ 12978295 ]
          Mark Thomas made changes -
          Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
          Mark Thomas made changes -
          Workflow jira [ 12732768 ] Default workflow, editable Closed status [ 12744614 ]
          Mark Thomas made changes -
          Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
          Paul King made changes -
          Status Resolved [ 5 ] Closed [ 6 ]
          Paul King made changes -
          Assignee Paul King [ paulk ]
          Resolution Won't Fix [ 2 ]
          Status Open [ 1 ] Resolved [ 5 ]
          Jochen Theodorou made changes -
          Component/s groovy-jdk [ 10750 ]
          Guillaume Delcroix made changes -
          Fix Version/s 1.7.x [ 15538 ]
          Jochen Theodorou made changes -
          Fix Version/s 1.6.x [ 15537 ]
          Guillaume Delcroix made changes -
          Link This issue is related to GROOVY-2838 [ GROOVY-2838 ]
          Guillaume Delcroix made changes -
          Link This issue duplicates GROOVY-1182 [ GROOVY-1182 ]
          Paul King made changes -
          Field Original Value New Value
          Link This issue is related to GROOVY-1182 [ GROOVY-1182 ]
          Guillaume Delcroix created issue -

            People

            • Assignee:
              Paul King
              Reporter:
              Guillaume Delcroix
            • Votes:
              16 Vote for this issue
              Watchers:
              11 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development