tomasz154/php-streams

View on GitHub
src/TerminalOperation/ToGenerator.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php


namespace T2\Streams\TerminalOperation;

use T2\Streams\Exception\EndOfStream;
use T2\Streams\Stream\StreamInterface;

class ToGenerator implements TerminalOperationInterface
{
    private $stream;

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

    public function getValue()
    {
        while (true) {
            try {
                yield $this->stream->getCurrent();
            } catch (EndOfStream $e) {
                break;
            }
        }
    }
}