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

Add inline() method to Object

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 2.5.0
    • groovy-jdk
    • None

    Description

      Deriving from discussion in GROOVY-5785, it would be nice if there were a way to call methods inline which return undesired return values. In the other issue, the example was calling removeAll() to find the difference between two sets:

      def extra = set1.clone()
      extra.removeAll(set2)
      println extra.size()

      You could use Object#with() here:

      println(set1.clone().with

      { removeAll(set2); it }

      .size())

      The inline() method implies "return it" at the end of the closure:

      println(set1.clone().inline

      { removeAll(set2) }

      .size())

      It might even make sense to define a new operator rather than a method, similar to the safe navigation operator:

      println(set1.clone()&.removeAll(set2).size())

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              balor123 Uri Moszkowicz
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: