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

every() from DefaultGroovyMethods returns true for empty iterator/list

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Won't Fix
    • 2.3.8, 2.4.0-beta-4
    • None
    • groovy-jdk
    • None

    Description

      assert [].every()
      assert [].every { it }
      assert [].every { it > 1 }
      

      Is this an expected behavior? In all the variants of every() in DefaultGroovyMethods the logic is simlar to

      BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
      for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) {
          if (!bcw.call(iter.next())) {
              return false;
          }
      }
      return true;
      

      So it defaults to true if !iter.hasNext(). Is this acceptable? Shouldn't it falsify based on empty List fails Groovy Truth?

      Attachments

        Activity

          People

            Unassigned Unassigned
            dmahapatro Dhiraj Mahapatro
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: