PHPackages                             xphere/lazzzy - 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. xphere/lazzzy

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

xphere/lazzzy
=============

Lazy collections for PHP

0.2(10y ago)130MITPHPPHP &gt;=5.4

Since Sep 21Pushed 10y ago1 watchersCompare

[ Source](https://github.com/xPheRe/lazzzy)[ Packagist](https://packagist.org/packages/xphere/lazzzy)[ Docs](http://github.com/xPheRe/Lazzzy)[ RSS](/packages/xphere-lazzzy/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

Lazzzy
======

[](#lazzzy)

Lazy collection library for PHP.

Wrap your iterables in a thin layer of pure lazyness, so they can be lazy-evaluated while you're being lazy too. :D

Why would I want that?
----------------------

[](#why-would-i-want-that)

Collections are everywhere, but you usually don't want to materialize them in each operation. That's where lazyness come in handy. This allows you to map and filter in zero initialization time, for later evaluation when the time is right.

Features
--------

[](#features)

- Convert anything into an iterable: arrays, iterators, functions, generators... you name it. \[\*\]
- Map and filter with multiple functions on initialization, execute once on evaluation
- Handles infinite iterators

\[\*\] planned

Compatibility
-------------

[](#compatibility)

Lazzzy requires PHP 5.4 or higher for basic usage.

Installation
------------

[](#installation)

Just use composer to add to your project:

```
composer require xphere/lazzzy@dev
```

Usage
-----

[](#usage)

NOTE: Lazzzy is still in alpha, so don't rely on current methods. Just sayin'

Functions
---------

[](#functions)

### Container::from(x) # lazy

[](#containerfromx--lazy)

Static function. Converts almost anything into an iterable. Returns a `Container` object wrapping the iterable.

```
use Lazzzy\Container;

$container = Container::from(range(0, 1000));
```

### Container::getIterator()

[](#containergetiterator)

Honors `\IteratorAggregate` interface so you can `foreach` over `Container`s.

### Container::toAssoc() # not lazy

[](#containertoassoc--not-lazy)

Iterates over the container, applying all transformations. Returns the resulting array.

```
use Lazzzy\Container;

$expected = ['a' => 0, 'b' => 1, 'c' => 2];
$container = Container::from($expected);

$values = $container->toAssoc();

$this->assertEquals($expected, $values);
```

### Container::toArray() # not lazy

[](#containertoarray--not-lazy)

Like `toAssoc` method, but discards keys.

```
use Lazzzy\Container;

$expected = [0, 1, 2];
$values = ['a' => 0, 'b' => 1, 'c' => 2];
$container = Container::from($expected);

$values = $container->toAssoc();

$this->assertEquals($expected, $values);
```

### Container::each(fn) # not lazy

[](#containereachfn--not-lazy)

Iterates over the container, executing `fn` on each iteration. Returns nothing.

```
use Lazzzy\Container;

$echo = function ($item) { echo $item, ', '; };
$container = Container::from(range(0, 5));

$container->each($echo);

/// Outputs "0, 1, 2, 3, " and returns nothing
```

### Container::map(fn) # lazy (a -&gt; b) -&gt; \[a\] -&gt; \[b\]

[](#containermapfn--lazy-a---b---a---b)

Calls `fn` transformation on each iteration of `[a]`.

```
use Lazzzy\Container;

$expected = [0, 2, 4, 6];
$double = function ($item) { return $item * 2; };
$container = Container::from(range(0, 3))
    ->map($double)
;

$actual = $container->toArray();

$this->assertSame($expected, $actual);
```

### Container::filter(fn) # lazy (a -&gt; Bool) -&gt; \[a\] -&gt; \[a\]

[](#containerfilterfn--lazy-a---bool---a---a)

Filters elements for which `fn` function returns truthy values.

```
use Lazzzy\Container;

$expected = [1, 3];
$odd = function ($item) { return $item % 2 === 1; };
$container = Container::from(range(0, 3))
    ->filter($odd)
;

$actual = $container->toArray();

$this->assertSame($expected, $actual);
```

### Container::take(number) # lazy n -&gt; \[a\] -&gt; \[a\]

[](#containertakenumber--lazy-n---a---a)

Takes `n` items from the iterator. `n` must be an integer greater than zero.

```
use Lazzzy\Container;

$expected = [0, 1];
$container = Container::from(range(0, 3))
    ->take(2)
;

$actual = $container->toArray();

$this->assertSame($expected, $actual);
```

### Container::takeWhile(fn) # lazy n -&gt; \[a\] -&gt; \[a\]

[](#containertakewhilefn--lazy-n---a---a)

Takes items while the condition `fn` is truthy.

```
use Lazzzy\Container;

$expected = [0, 1];
$notEqualsTwo = function ($item) { return $item !== 2; };
$container = Container::from(range(0, 3))
    ->takeWhile($notEqualsTwo)
;

$actual = $container->toArray();

$this->assertSame($expected, $actual);
```

More to come

- Container::skip(n)
- Container::skipUntil(fn)
- Container::fold(fn, x?)
- Container::foldr(fn, x?)
- Container::find(fn)
- Container::every(fn)
- Container::any(fn)
- Container::size()

Contributions
-------------

[](#contributions)

Please contribute with the project on [GitHub](https://github.com/xPheRe/lazzzy)

Author
------

[](#author)

Berny Cantos Contact: GitHub: [xPheRe](//github.com/xPheRe)Twitter: [xPheRe](//twitter.com/xPheRe)

License
-------

[](#license)

Lazzzy is licensed under the MIT License. See LICENSE file for full details.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 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 ~325 days

Total

2

Last Release

3929d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/608fb6577803c78b31cf7ade299388f44ffe2e13f4cc773c331944773cca6b97?d=identicon)[xphere](/maintainers/xphere)

---

Top Contributors

[![xphere](https://avatars.githubusercontent.com/u/170968?v=4)](https://github.com/xphere "xphere (29 commits)")

---

Tags

iteratorcollectionlazyfunctional

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/xphere-lazzzy/health.svg)

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

###  Alternatives

[nikic/iter

Iteration primitives using generators

1.1k5.9M38](/packages/nikic-iter)[loophp/collection

A (memory) friendly, easy, lazy and modular collection class.

745663.8k13](/packages/loophp-collection)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)[ihor/nspl

Non-standard PHP library (NSPL) - functional primitives toolbox and more

381368.5k](/packages/ihor-nspl)[cerbero/lazy-json

Framework-agnostic package to load JSONs of any dimension and from any source into Laravel lazy collections.

254309.8k1](/packages/cerbero-lazy-json)[chdemko/sorted-collections

Sorted Collections for PHP &gt;= 8.2

222.5M3](/packages/chdemko-sorted-collections)

PHPackages © 2026

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