Beispiel #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));
 }
Beispiel #2
0
 /**
  * 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));
 }
Beispiel #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));
 }