function _reduceRight($list, $iterator, $memo, $context = NULL)
{
    return Underscore::reduceRight($list, $iterator, $memo, $context);
}
Exemplo n.º 2
0
 /**
  * @tags collections
  */
 public function testReduceRight()
 {
     // it should provide the memo, the value, the index and the list to the reduction function (in that order)
     $test = $this;
     _::reduceRight(['a' => 1, 'b' => 2, 'c' => 3], function ($m, $v, $k, $l) use($test) {
         $test->integer($v);
         $test->string($k);
         $test->array($l);
         $test->boolean(is_null($m))->isTrue();
         return $m;
     }, null);
     $this->typeTolerant([[1, 2], [3, 4], [5, 6]], [5, 6, 3, 4, 1, 2], function ($in, $out) {
         $this->variable(_::reduceRight($in, function ($m, $v) {
             return array_merge($m, $v);
         }, []))->isEqualTo($out);
     }, [0, -1]);
     // it should be possible to specify a context for reduction function
     $this->variable(_::reduceRight([[1, 2], [3, 4], [5, 6]], function ($m, $v) {
         $v[0] *= $this->mult;
         $v[1] *= $this->mult;
         return array_merge($m, $v);
     }, [], (object) ['mult' => 2]))->isEqualTo([10, 12, 6, 8, 2, 4]);
 }