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

List operations minus and plus not symmetrical

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-beta-10
    • 1.0-JSR-5
    • groovy-jdk
    • None

    Description

      groovy> x = [1,1] - []
      groovy> println x
      groovy> go
      [1]

      groovy> x = [1,1] + []
      groovy> println x
      groovy> go
      [1, 1, []]

      I understand that minus doesn't mean to remove elements
      but to return the difference of two collections.
      It does return a set.

      Plus() in contrast adds an element instead of returning
      the union of elements. As a second difference, the
      result is a list, not a set.


      There are operations for sets like 'union' and 'difference' that have
      this behaviour. And sets have no doubled entries by definition.

      For lists we have 'add' and 'remove'.

      The problem is that the current implementation of plus() and minus()
      is a mix between the two concepts.


      suggestion:
      make different implementations for sets and lists.

      • for sets with union/difference meaning
      • for lists with add/remove meaning

      Attachments

        Activity

          People

            guillaume Guillaume Sauthier
            codevise Dierk König
            Votes:
            2 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: