PHPackages                             tobento/service-iterable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. tobento/service-iterable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

tobento/service-iterable
========================

Iterables and iterators

2.0(7mo ago)0270↓75%11MITPHPPHP &gt;=8.4

Since Oct 28Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/service-iterable)[ Packagist](https://packagist.org/packages/tobento/service-iterable)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-service-iterable/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (4)Used By (11)

Iterable Service
================

[](#iterable-service)

Iterable helper and common iterators used in other services.

Table of Contents
-----------------

[](#table-of-contents)

- [Getting started](#getting-started)
    - [Requirements](#requirements)
    - [Highlights](#highlights)
- [Documentation](#documentation)
    - [Iterable](#iterable)
    - [Iterators](#iterators)
        - [Chunk Iterator](#chunk-iterator)
        - [Modify Iterator](#modify-iterator)
        - [Item Factory Iterator](#item-factory-iterator)
        - [Json File Iterator](#json-file-iterator)
- [Credits](#credits)

---

Getting started
===============

[](#getting-started)

Add the latest version of the iterable service project running this command.

```
composer require tobento/service-iterable

```

Requirements
------------

[](#requirements)

- PHP 8.4 or greater

Highlights
----------

[](#highlights)

- Framework-agnostic, will work with any project
- Decoupled design

Documentation
=============

[](#documentation)

Iterable
--------

[](#iterable)

**toArray**

Converts any iterable to an array.

```
use Tobento\Service\Iterable\Iter;

$iterable = ['key' => 'value'];

$array = Iter::toArray(iterable: $iterable);
```

**toIterator**

Converts any iterable to an iterator.

```
use Tobento\Service\Iterable\Iter;
use Iterator;

$iterable = ['key' => 'value'];

$iterator = Iter::toIterator(iterable: $iterable);

var_dump($iterator instanceof Iterator);
// bool(true)
```

Iterators
---------

[](#iterators)

### Chunk Iterator

[](#chunk-iterator)

```
use Tobento\Service\Iterable\ChunkIterator;

$iterator = new ChunkIterator(
    iterable: range(1, 10),
    chunkLength: 2,
);

foreach($iterator as $chunk) {} // [1, 2], [3, 4], ...
```

### Modify Iterator

[](#modify-iterator)

```
use Tobento\Service\Iterable\ModifyIterator;

$iterator = new ModifyIterator(
    iterable: range(1, 5),
    modifier: function(int $number): int {
        return $number * 10;
    }
);

foreach($iterator as $number) {} // 10, 20, ...
```

### Item Factory Iterator

[](#item-factory-iterator)

You may use the item factory iterator to seed items and use the [Seeder Service](https://github.com/tobento-ch/service-seeder) to generate fake data.

```
use Tobento\Service\Iterable\ItemFactoryIterator;
use Tobento\Service\Seeder\Str;
use Tobento\Service\Seeder\Arr;

$callable = function(): array {
    return [
        'name' => Str::string(10),
        'color' => Arr::item(['green', 'red', 'blue']),
    ];
};

$iterator = new ItemFactoryIterator(
    factory: $callable,
    create: 10
);
```

### Json File Iterator

[](#json-file-iterator)

```
use Tobento\Service\Iterable\JsonFileIterator;

$iterator = new JsonFileIterator(
    file: 'private/src/file.json',
);

foreach($iterator as $key => $item) {}
```

For large files you may consider [Json Maschine](https://github.com/halaxa/json-machine).

Credits
=======

[](#credits)

- [Tobias Strub](https://www.tobento.ch)
- [All Contributors](../../contributors)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance62

Regular maintenance activity

Popularity15

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~354 days

Total

4

Last Release

237d ago

Major Versions

1.x-dev → 2.02025-09-24

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/055d6a1b5c2384bb179c75ab0b55914231d898fdc4dffeb30770f81200e52206?d=identicon)[TOBENTOch](/maintainers/TOBENTOch)

---

Top Contributors

[![tobento-ch](https://avatars.githubusercontent.com/u/16684832?v=4)](https://github.com/tobento-ch "tobento-ch (6 commits)")

---

Tags

phppackageiteratortobentoiterable

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tobento-service-iterable/health.svg)

```
[![Health](https://phpackages.com/badges/tobento-service-iterable/health.svg)](https://phpackages.com/packages/tobento-service-iterable)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
