PHPackages                             no22/sloth - 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. no22/sloth

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

no22/sloth
==========

simple lazy application iterator

172PHP

Since May 4Pushed 13y ago1 watchersCompare

[ Source](https://github.com/no22/Sloth)[ Packagist](https://packagist.org/packages/no22/sloth)[ RSS](/packages/no22-sloth/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Sloth
=====

[](#sloth)

Sloth is a simple lazy application iterator for PHP 5.2 or later.

Setup
-----

[](#setup)

```
    require "Sloth/Autoload.php";
```

Create iterator object
----------------------

[](#create-iterator-object)

```
    $iter = Sloth::iter($array_or_iterator);
```

or

```
    $iter = Sloth::iter($initialValue, $functionCallback);
```

Lazy map
--------

[](#lazy-map)

```
    function foo($n)
    {
        echo "foo called.\n";
        return $n * $n;
    }

    $iter = Sloth::iter(array(1,2,3,4,5))->map('foo');

    foreach ($iter as $e) {
        echo $e . "\n";
    }
```

```
    foo called.
    1
    foo called.
    4
    foo called.
    9
    foo called.
    16
    foo called.
    25
```

Infinite sequense
-----------------

[](#infinite-sequense)

for PHP 5.2

```
    $even = Sloth::iter(0, Sloth::fn('$n + 2'));
    $evenLessThan10 = $even->takeWhile(Sloth::fn('$n < 10'));
    foreach ($evenLessThan10 as $e) {
        echo $e . "\n";
    }
```

for PHP 5.3

```
    $even = Sloth::iter(0, function($n){return $n + 2;});
    $evenLessThan10 = $even->takeWhile(function($n){return $n < 10;});
    foreach ($evenLessThan10 as $e) {
        echo $e . "\n";
    }
```

License
-------

[](#license)

Sloth is dual Licensed MIT and GPLv3. You may choose the license that fits best for your project.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/153230?v=4)[Hiroyuki OHARA](/maintainers/no22)[@no22](https://github.com/no22)

---

Top Contributors

[![no22](https://avatars.githubusercontent.com/u/153230?v=4)](https://github.com/no22 "no22 (11 commits)")

### Embed Badge

![Health badge](/badges/no22-sloth/health.svg)

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

###  Alternatives

[kreait/gcp-metadata

Get the metadata from a Google Cloud Platform environment.

654.9M1](/packages/kreait-gcp-metadata)[imgix-wordpress/images-via-imgix

imgix WordPress plugin

555.6k](/packages/imgix-wordpress-images-via-imgix)

PHPackages © 2026

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