function _some($list, $iterator = NULL, $context = NULL)
{
    return Underscore::some($list, $iterator, $context);
}
Esempio n. 2
0
 /**
  * @tags collections
  */
 public function testSome()
 {
     $even = function ($v) {
         return !($v & 1);
     };
     // it should work with arrays, objects and iterators
     $this->typeTolerant([1, 3, 4, 5], null, function ($in, $out) use($even) {
         $this->boolean(_::some($in, $even))->isTrue();
     }, [0, -1]);
     // the truth test should be optionnal
     $this->boolean(_::some([false, 0, "0", null, true, 2]))->isTrue();
     // it should return true if at leat one item in the list pass the truth test
     $this->boolean(_::some([1, 3, 4, 5], $even))->isTrue();
     // it should return false if all items in the list doesn't pass the truth test
     $this->boolean(_::some([1, 3, 5, 7], $even))->isFalse();
     // it should stop the list iteration when an item pass the truth test
     $i = 0;
     _::some([1, 3, 4, 5], 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(_::some([1, 3, 4, 5], function ($v) {
         return $v % $this->mod == 0;
     }, (object) ['mod' => 2]))->isTrue();
     // it should return false if the list is empty
     $this->boolean(_::some([], function ($v) {
         return true;
     }))->isFalse();
 }