Ejemplo n.º 1
0
 /**
  * Get the sum of the stream.
  *
  * This is a closing operation (it calls <code>$this->close()</code> internally).
  *
  * @return Optional an optional result
  * @see \monad\Stream::close()
  */
 public function sum() : Optional
 {
     return $this->bindMonad(sequence(conditionally(negation(is_empty), array_sum), optional));
 }
Ejemplo n.º 2
0
Archivo: Chain.php Proyecto: iddqdby/f7
 /**
  * Apply function only if the value is not NULL.
  *
  * @see \monad\Monad::bind($function)
  * @see \monad\Chain::emptyChain()
  */
 public function continue(callable $function) : Chain
 {
     return parent::bind(conditionally(negation(is_null), $function));
 }
Ejemplo n.º 3
0
 /**
  * Map a value of the monad if it is present.
  *
  * See <code>isPresent()</code>.
  *
  * @param callable $function the mapper
  * @return Optional a new Optional if the value was present, or this otherwise
  */
 public function ifPresent(callable $function) : Optional
 {
     return $this->bind(conditionally(negation(is_null), $function));
 }