Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3526

It would be nice to have a GDK method for replacing particular items in a list, i.e. combining findAll and collect

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Won't Fix
    • None
    • None
    • None
    • None

    Description

      Desired usage:

      def words = ['Ant', 'Dog']
      def aWord = { w -> w.startsWith('A') }
      def makeLower = { w -> w.toLowerCase() }
      words.updateMatching(aWord, makeLower)
      

      Groovy code snippet elaborating desired behavior (for a mutating version, but perhaps one that returns a modified list is the better way to go):

      (0..<words.size()).each { i ->
          def w = words[i]
          if (aWord(w)) words[i] = makeLower(w)
      }
      println words
      

      Attachments

        1. GROOVY-3526-rvelascor.txt
          3 kB
          Rodolfo Velasco

        Issue Links

          Activity

            People

              paulk Paul King
              paulk Paul King
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: