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

Align intersect which takes a closure/comparator ordering to be the same as other languages.

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 4.0.0-beta-2
    • None

    Description

      Consider the following code:

      def first = ['a', 'B', 'c', 'd']
      def second = ['b', 'C', 'd', 'e']
      def lower = { one, two -> one.toLowerCase() <=> two.toLowerCase() }
      assert first.intersect(second) == ['d']
      assert first.intersect(second, lower) == ['b', 'C', 'd']
      assert second.intersect(first, lower) == ['B', 'c', 'd']
      

      In most languages (e.g. Haskell, C#, PureScript) the result shown for the last two lines are reversed. The elements in the result are drawn from the first operand which match according to the comparator with an element in the second. For identity comparators they will be the same result but for the more unusual case of a projecting comparator (as shown here), Groovy is drawing elements from the second operand. This issue is to reverse that behavior as a breaking change for Groovy 4 only.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 40m
                40m