Ejemplo n.º 1
0
Archivo: Chain.php Proyecto: iddqdby/f7
 /**
  * Invoke a value if it is callable.
  *
  * @param array $args optional array of arguments to pass to the optional callable
  * @return Chain the result of the invocation wrapped into a Chain, or empty Chain
  */
 public function invokeArray(array $args = []) : Chain
 {
     return $this->continue(conditionally(is_callable, curry(reverse(call_user_func_array), 2)($args)));
 }
Ejemplo n.º 2
0
 /**
  * Iteratively reduce the stream to a single value using a callback function.
  *
  * Method applies iteratively the callback function to elements and keys of
  * the stream, so as to reduce it to a single value.
  *
  * This is a closing operation (it calls <code>$this->close()</code> internally).
  *
  * @param callable $callback the callback to apply to each element and key;
  * current intermediate result will be passed as the first argument
  * (in the case of the first iteration it instead holds the value of $initial),
  * current value will be passed as the second one, current key will be passed
  * as the third one; callback must return new intermediate result
  * @param mixed $initial initial value (optional, default is NULL)
  * @return Optional an optional result
  * @see \convert\traversable_reduce
  * @see \monad\Stream::close()
  */
 public function reduce(callable $callback, $initial = null) : Optional
 {
     return $this->bindMonad(sequence(curry(traversable_reduce, 3)($callback)($initial), optional));
 }