承接 pcrov/iteratorstackiterator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pcrov/iteratorstackiterator

最新稳定版本:1.0.2

Composer 安装命令:

composer require pcrov/iteratorstackiterator

包简介

Iterates over a stack of iterators, discarding them as they complete.

README 文档

README

Build Status Coverage Status License Latest Stable Version

Iterates over a stack of iterators, discarding them as they complete.

Requirements

PHP 7 with either the Ds extension or its polyfill. The php-ds polyfill will be installed automatically when IteratorStackIterator is installed via composer and only loaded if the Ds extension is not installed and enabled.

Installation

To install with composer:

composer require pcrov/iteratorstackiterator

Usage

This iterator implements OuterIterator, adding push() and pop() methods to add and remove inner iterators, respectively.

push() will return the new size of the stack. pop() will return the iterator popped from the top.

The values returned from key() and current() will always be from the current position of the top iterator on the stack.

next() moves the cursor of the iterator at the top of the stack. If that iterator is no longer valid it is removed, as are any others that have completed until a valid iterator is found or the stack is empty.

rewind() will rewind all iterators left on the stack.

Example 1

$stack = new \pcrov\IteratorStackIterator();
$stack->push(
    new ArrayIterator([1, 2, 3]),
    new ArrayIterator([4, 5, 6]),
    new ArrayIterator([7, 8, 9])
);

foreach ($stack as $value) {
    echo $value;
}

// output: 789456123

Iterators can be added to the stack after iteration has already begun. They will not automatically be rewound when added, so you should call rewind() on them prior if needed.

Example 2

$stack = new \pcrov\IteratorStackIterator();
$stack->push(
    new ArrayIterator([1, 2, 3]),
    new ArrayIterator([4, 5, 6])
);
$stack->rewind();

while ($stack->valid()) {
    $value = $stack->current();
    echo $value;
    $stack->next();

    if ($value === 2) {
        $stack->push(new ArrayIterator([7, 8, 9]));
    }
}

// output: 456127893

Note that next() is called prior to pushing a new iterator, otherwise when the stack ran back down that position would be repeated (which in this case result would result in an infinite loop.)

If an inner iterator's cursor position is manipulated from outside the stack iterator the resulting behavior is undefined.

统计信息

  • 总下载量: 15.11k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固