__construct() public method

Construct a new stream from a traversable source.
public __construct ( Traversabl\Traversable | array $source )
$source Traversabl\Traversable | array The source to create the stream from.
Example #1
0
 /**
  * Construct a limited stream.
  *
  * @param type $source
  * @param type $limit The number of items to show, at most.
  * @throws InvalidArgumentException
  */
 public function __construct($source, $limit)
 {
     parent::__construct($source);
     if ($limit < 0) {
         throw new InvalidArgumentException("Limit should be at least 0.");
     }
     $this->limit = $limit;
 }
Example #2
0
 /**
  * Construct a new skipping stream.
  *
  * @param Traversable $source
  * @param int $toSkip The number of items to skip.
  * @throws InvalidArgumentException if the number to skip is less than 0.
  */
 public function __construct($source, $toSkip)
 {
     parent::__construct($source);
     if ($toSkip < 0) {
         throw new InvalidArgumentException("To skip should be >= 0.");
     }
     $this->toSkip = $toSkip;
 }
Example #3
0
 /**
  * Construct a new flatmap stream.
  *
  * @param iterable $source The source to read from.
  * @param callable $unpacker Some callback that convert source stream items
  * to something iterable.
  */
 public function __construct($source, callable $unpacker)
 {
     parent::__construct($source);
     $this->unpacker = $unpacker;
 }
 public function __construct($source, callable $callback)
 {
     parent::__construct($source);
     $this->callback = $callback;
 }
Example #5
0
 public function __construct($source, callable $sort = null)
 {
     parent::__construct($source);
     $this->sort = $sort;
 }
 /**
  * Construct a unique stream.
  *
  * This stream will yield each distinct value only once.
  *
  * @param \Traversable $source
  * @param boolean $strict Whether to use strict comparisons when determining uniqueness.
  */
 public function __construct($source, $strict)
 {
     parent::__construct($source);
     $this->strict = $strict;
 }