iterate() public method

Returning false will break the iteration loop.
public iterate ( callable $function ) : void
$function callable The iteration function, parameters are passed as ($value, $key)
return void
Esempio n. 1
0
 /**
  * @dataProvider everything
  */
 public function testIterateWillStopAfterReturningFalse(\Pinq\ITraversable $traversable, array $data)
 {
     if ($traversable->count() < 3) {
         return;
     }
     $count = 0;
     $traversable->iterate(function ($value, $key) use(&$count) {
         $count++;
         //Must use strict equality
         if ($count === 1) {
             return '';
         } elseif ($count === 2) {
             return 0;
         } elseif ($count === 3) {
             return false;
         }
     });
     $this->assertSame($count, 3);
 }