phpstreams\Stream::any PHP Method

any() public method

This method short-circuits, so if any item matches the predicate, no further items are evaluated.
public any ( callable $predicate = null ) : boolean
$predicate callable
return boolean
    public function any(callable $predicate = null)
    {
        if ($predicate === null) {
            $predicate = Functions::identity();
        }
        foreach ($this as $value) {
            if ($predicate($value)) {
                return true;
            }
        }
        return false;
    }

Usage Example

Example #1
0
 public function testAny()
 {
     $this->assertTrue((new Stream([false, false, true, false]))->any());
     $this->assertFalse((new Stream([false, false, false, false]))->any());
     $stream = new Stream([1, 2, 3, 4, 42]);
     $this->assertTrue($stream->any(function ($value) {
         return $value == 42;
     }));
 }