[ 
https://issues.apache.org/jira/browse/GROOVY-7207?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17451451#comment-17451451
 ] 

Paul King commented on GROOVY-7207:
-----------------------------------

It would be worth checking what other languages do here but the current 
implementation assumes {{every}} should fail if it finds a single element in 
the list which doesn't pass the predicate.

> every() from DefaultGroovyMethods returns true for empty iterator/list
> ----------------------------------------------------------------------
>
>                 Key: GROOVY-7207
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7207
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 2.3.8, 2.4.0-beta-4
>            Reporter: Dhiraj Mahapatro
>            Priority: Major
>
> {code:java}
> assert [].every()
> assert [].every { it }
> assert [].every { it > 1 }
> {code}
> Is this an expected behavior? In all the variants of {{every()}} in 
> {{DefaultGroovyMethods}} the logic is simlar to
> {code:java}
> BooleanClosureWrapper bcw = new BooleanClosureWrapper(closure);
> for (Iterator iter = InvokerHelper.asIterator(self); iter.hasNext();) {
>     if (!bcw.call(iter.next())) {
>         return false;
>     }
> }
> return true;
> {code}
> So it defaults to true if {{!iter.hasNext()}}. Is this acceptable? Shouldn't 
> it falsify based on empty List fails Groovy Truth?



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to