PHP - função Ds Deque reduce ()

A função Ds \ Deque :: reduce () pode reduzir o deque a um único valor usando uma função de retorno de chamada.

Sintaxe

public mixed Ds\Deque::reduce( callable $callback [, mixed $initial ] )

A função Ds \ Deque :: reduce () pode retornar o valor do retorno de chamada final.

Exemplo 1

<?php 
   $deque = new \Ds\Deque([10, 20, 30, 40, 50]); 
   echo("The elements in deque: \n"); 
   print_r($deque); 
   
   $func = function($carry, $element) { 
      return $carry + $element; 
   }; 
   echo("\n The deque after reduced into single element:");   
   var_dump($deque->reduce($func, 3)); 
?>

Exemplo 2

<?php 
   $deque = new \Ds\Deque([10, 20, 30, 40, 50]); 
   echo("The elements in deque: \n"); 
   print_r($deque); 
   
   $func = function($carry, $element) { 
      return $carry * $element + 30; 
   }; 
   echo("\n The deque after reduced into single element:"); 
   var_dump($deque->reduce($func, 10)); 
?>