コード例 #1
0
function _find($list, $iterator, $context = NULL)
{
    return Underscore::find($list, $iterator, $context);
}
コード例 #2
0
ファイル: Underscore.php プロジェクト: brombal/underscore.php
 /**
  * @tags collections
  */
 public function testFind()
 {
     $even = function ($v) {
         return !($v & 1);
     };
     // it should return the first value that match the truth test and work with arrays, objects and iterators
     $this->typeTolerant([1, 2, 3, 4], 2, function ($in, $out) use($even) {
         $this->integer(_::find($in, $even))->isEqualTo($out);
     }, [0, -1]);
     // it should return null when no value match the truth test
     $this->variable(_::find([1, 3, 5], $even))->isNull();
     // it should be possible to specify a context for the thruth test
     $this->variable(_::find([1, 2, 3, 4], function ($v) {
         return $v % $this->mod == 0;
     }, (object) ['mod' => 2]))->isEqualTo(2);
     // it should stop iterating over the list once an element is found
     $i = 0;
     _::find([1, 2, 3, 4], function ($v) use(&$i) {
         $i++;
         return !($v & 1);
     });
     $this->variable($i)->isEqualTo(2);
 }