function _every($list, $iterator = NULL, $context = NULL)
{
    return Underscore::every($list, $iterator, $context);
}
Пример #2
0
 /**
  * @tags collections
  */
 public function testEvery()
 {
     $even = function ($v) {
         return !($v & 1);
     };
     // it should work with arrays, objects and iterators
     $this->typeTolerant([2, 4, 6, 8], null, function ($in, $out) use($even) {
         $this->boolean(_::every($in, $even))->isTrue();
     }, [0, -1]);
     // the truth test should be optionnal
     $this->boolean(_::every([1, true, "1", [null], (object) []]))->isTrue();
     // it should return true if all items in the list passes the truth test
     $this->boolean(_::every([2, 4, 6, 8], $even))->isTrue();
     // it should return false if at leat one item in the list doesn't pass the truth test
     $this->boolean(_::every([2, 4, 5, 6], $even))->isFalse();
     // it should stop the list iteration when an item doesn't pass the truth test
     $i = 0;
     _::every([2, 4, 5, 6], function ($v) use(&$i, $even) {
         $i++;
         return $even($v);
     });
     $this->variable($i)->isEqualTo(3);
     // it should be possible to specify a context for the truth test
     $this->boolean(_::every([2, 4, 6, 8], function ($v) {
         return $v % $this->mod == 0;
     }, (object) ['mod' => 2]))->isTrue();
     // it should return true if the list is empty
     $this->boolean(_::every([], function ($v) {
         return true;
     }))->isTrue();
 }