PHPackages                             ebeacon/iterutil - 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. ebeacon/iterutil

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

ebeacon/iterutil
================

Creates iterators for arrays or any iterable, with lazily evaluated (memory efficient) transformations. Heavily inspired by Rust's iterators.

0.6(1y ago)0630↓33.3%1MITPHPPHP &gt;=5.6.0

Since Nov 4Pushed 1y agoCompare

[ Source](https://github.com/EbeaconDigital/iterutil)[ Packagist](https://packagist.org/packages/ebeacon/iterutil)[ RSS](/packages/ebeacon-iterutil/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (1)

IterUtil
========

[](#iterutil)

IterUtil is an iterator builder for PHP that enables you to apply a variety of transformations on the data held in any `iterable` without modifying the original's contents. All "non-consuming" methods are lazily evaluated, saving memory usage as well as CPU time. It is mostly inspired by Rust's [Iterator trait](https://doc.rust-lang.org/std/iter/trait.Iterator.html), with some alterations made for PHP coding conventions and its somewhat unique situation with associative arrays.

At present, it supports PHP all the way back through 5.6, though 7.4+ is certainly recommended if only to have access to the arrow function syntax!

General Constructor
-------------------

[](#general-constructor)

```
$fruits = ["apples", "bananas", "oranges"];
$iter = IterUtil::from($fruits);

```

`IterUtil::from` creates a new `IterUtil` instance from any array, or any object that implements `Traversable`. At this point, it is effectively just an iterator wrapping the iterator you provided. No other work is performed, but now you can apply transformations.

Transformations
---------------

[](#transformations)

```
$vowels = ["A", "E", "I", "O", "U"];
$fruits = ["Apples", "Bananas", "oranges"];
$iter = IterUtil::from($fruits)
    ->map(fn($fruit) => ucfirst($fruit))
    ->filter(fn($fruit) => in_array(substr($fruit, 0, 1), $vowels))
    ->keys();

```

Transformations are both lazy and chainable. All that we've done is modify the iterator itself. `$fruits` is unchanged and we haven't even begun to iterate yet.

Consumers
---------

[](#consumers)

Other methods will consume the iterator, perform any transformations in the order in which they were applied, and produce some sort of result. One of these, `collect()`, produces an array:

```
$vowels = ["A", "E", "I", "O", "U"];
$fruits = ["Apples", "Bananas", "oranges"];
$result = IterUtil::from($fruits)
    ->map(fn($fruit) => ucfirst($fruit))
    ->filter(fn($fruit) => in_array(substr($fruit, 0, 1), $vowels))
    ->keys()
    ->collect();

```

`$result` is now equal to `[0, 2]`, which are the keys of the fruits that begin with vowels. The original list in `$fruits` is actually only iterated over a single time, and is the equivalent of writing:

```
$vowels = ["A", "E", "I", "O", "U"];
$fruits = ["Apples", "Bananas", "oranges"];
$result = [];
foreach ($fruits as $key => $fruit) {
    if (in_array(substr(ucfirst($fruit), 0, 1), $vowels)) {
        $result[] = $key;
    }
}

```

`reduce()` is another common example:

```
$cart = [
    ["name" => "Apples", "qty" => 2, "price" => .30],
    ["name" => "Bananas", "qty" => 1, "price" => 10.00],
    ["name" => "Oranges", "qty" => 3, "price" => .45],
];
$subtotal = IterUtil::from($cart)
    ->reduce(fn($acc, $item) => $acc + ($item["qty"] * $item["price"]), 0);

```

Specialized Constructors
------------------------

[](#specialized-constructors)

`IterUtil::fromString($str, $delimiter = "")` will allow you to iterate over a string, split on the delimiter. (If the delimiter is an empty string or not provided, it will split the string into individual characters.)

```
$hello = "Hello, World!";
$words = IterUtil::fromString($hello, " ")
    ->collect();
// $words is now equal to ["Hello,", "World!"]

```

`IterUtil::range($start = 0, $end = PHP_INT_MAX, $step = 1)` can generate an (inclusive) range of numbers.

```
$numbers = IterUtil::range(0, 7)
    ->collect();
// $numbers is now equal to [0, 1, 2, 3, 4, 5, 6, 7]

```

`IterUtil::repeat($value, $n = INF)` will repeat the same value over and over again.

```
$aBunchOfZeroes = IterUtil::repeat(0, 8)
    ->collect();
// $aBunchOfZeroes is now equal to [0, 0, 0, 0, 0, 0, 0, 0]

```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

560d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/187050793?v=4)[eb-rherriman](/maintainers/eb-rherriman)[@eb-rherriman](https://github.com/eb-rherriman)

---

Top Contributors

[![eb-rherriman](https://avatars.githubusercontent.com/u/187050793?v=4)](https://github.com/eb-rherriman "eb-rherriman (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ebeacon-iterutil/health.svg)

```
[![Health](https://phpackages.com/badges/ebeacon-iterutil/health.svg)](https://phpackages.com/packages/ebeacon-iterutil)
```

###  Alternatives

[panakour/analytics

Get whatever data you want from google analytics.

267.6k](/packages/panakour-analytics)[seanstewart/plan-config

Plan config allows you to easily define attributes and limits for your SaaS application subscription plans.

314.0k](/packages/seanstewart-plan-config)[irail/stations

Use the Belgian railway's station in your PHP project

332.3k](/packages/irail-stations)

PHPackages © 2026

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