tomasz154/php-streams

View on GitHub
src/Operation/Filter.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace T2\Streams\Operation;

use T2\Streams\Stream\StreamInterface;

class Filter implements StreamInterface
{
    private $stream;
    private $callable;

    public function __construct(StreamInterface $stream, callable $callable)
    {
        $this->stream = $stream;
        $this->callable = $callable;
    }

    public function getCurrent()
    {
        do {
            $current = $this->stream->getCurrent();
        } while (!call_user_func($this->callable, $current));

        return $current;
    }

    public function next()
    {
        $this->getCurrent();
    }

    public function isBounded()
    {
        return $this->stream->isBounded();
    }
}