-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Description
Would it be nice to have some kind of fluent interface?
That would allow for really readable code like:
toIter([1, 2, 3, 4, 5, 6])
->filter(function($v) { return $v % 2 === 0; })
->slice(0, 1)
I think it can be implemented relatively simply:
class Test implements \IteratorAggregate {
private $iterator;
public function __construct(iterable $iterator)
{
$this->iterator = \iter\toIter($iterator);
}
public function getIterator()
{
return $this->iterator;
}
public function filter(\Closure $predicate) {
return new self(\iter\filter($predicate, $this));
}
}
What do you think?
I could implement this and if we alter toIter to return the new type, it wouldn't even break backwards compatibility since people are expecting a generator.
ragboyjrenleur
Metadata
Metadata
Assignees
Labels
No labels