protected function __construct($value) { if ($value instanceof \IteratorAggregate) { $value = $value->getIterator(); } else { if (!$value instanceof \Traversable) { if (!is_array($value)) { $value = [$value]; } $value = new \ArrayIterator($value); } } parent::__construct($value); }
/** * 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)); }
/** * {@inheritDoc} * * This is a closing operation (it calls <code>$this->close()</code> internally). * * @see \monad\Monad::extract() * @see \monad\Stream::close() */ public function extract() : array { $value = parent::extract(); $this->close(); return $value; }