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

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

Agile BoardAttach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    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

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Issue deployment