PHPackages                             anon767/phpstream - 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. anon767/phpstream

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

anon767/phpstream
=================

stream api for php

110PHP

Since Feb 1Pushed 8y agoCompare

[ Source](https://github.com/anon767/PHP-Stream-API)[ Packagist](https://packagist.org/packages/anon767/phpstream)[ RSS](/packages/anon767-phpstream/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Stream API
==============

[](#php-stream-api)

This library is based upon the Stream-Api from Java and the Array-Prototype from Javascript

()

([https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global\_Objects/Array/map](https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Array/map))

If you like functional patterns, readable code or immutable Datatypes and miss it in PHP, you should definitely give it a try.

Dependencies
------------

[](#dependencies)

1. PHP &gt;= 5
2. PHPUnit for development

install
-------

[](#install)

execute `composer require anon767/phpstream`

or add following to your composer.json

```
"require": {
    "anon767/phpstream": "*"
  }

```

Usage
-----

[](#usage)

Stream-methods that return single elements from an array wrap those into Cells (compare Java optional).

Those values inside can be accessed via `$cell->unwrap()` or `$cell->orElse($default)`.

unwrapping a cell with a null value inside throws a "NoElementException"

You can transform any traditional Array into a Stream either like that.

```
use Stream/Stream;
$array = [1,2,3,4,5,6,7,8,9,10];
$stream = new Stream($array);
```

or like that

```
use Stream/Stream;
$array = [1,2,3,4,5,6,7,8,9,10];
$stream = Stream::asStream($array);
```

The most functions from the Java Stream Api are implemented.

Examples
--------

[](#examples)

#### get the first even number from an array

[](#get-the-first-even-number-from-an-array)

```
$array = [1,2,3,4,5,6,7,8,9,10];
$onlyEvenNumbers = Stream::asStream($array)->filter(function($v){return $v%2==0;});
$firstEvenNumber = $onlyEvenNumbers->first()->unwrap();
```

or in one line

```
$firstEvenNumber = Stream::asStream([1,2,3,4,5,6,7,8,9,10])->filter(function($v){return $v%2==0;})->first()->unwrap();
```

#### square all numbers in an array

[](#square-all-numbers-in-an-array)

```
$array = [1,2,3,4,5,6,7,8,9,10];
$squares = Stream::asStream($array)->map(function($v){return $v*$v;});
```

#### Print all numbers in an array

[](#print-all-numbers-in-an-array)

```
$array = [1,2,3,4,5,6,7,8,9,10];
Stream::asStream($array)->forEach(function($v){echo $v;});
```

#### ArrayList

[](#arraylist)

The ArrayList class extends ArrayObject and can be therefore used just like a normal PHP array. Although it can be directly converted to a Stream

```
$a = new ArrayList();
$a[] = 1;
$a[] = 2;
$a[] = 3;
echo $a->toStream()->first()->orElse(null); // prints 1
```

License
-------

[](#license)

MIT

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

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://www.gravatar.com/avatar/6e17da740e35c6f38186b3f3961f96f8d78f0ae1660b9bc11163131ca65092e6?d=identicon)[anon767](/maintainers/anon767)

---

Top Contributors

[![anon767](https://avatars.githubusercontent.com/u/20929982?v=4)](https://github.com/anon767 "anon767 (8 commits)")

### Embed Badge

![Health badge](/badges/anon767-phpstream/health.svg)

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

###  Alternatives

[pixelfear/composer-dist-plugin

Downloads distributable assets to be used in packages so you don't have to commit them.

303.8M66](/packages/pixelfear-composer-dist-plugin)[yidas/pagination

PHP Paginator with Pager Widget (pure PHP, CI, Yii, Laravel support)

2516.4k](/packages/yidas-pagination)[webignition/absolute-url-deriver

Derives an absolute URL from relative and source URLs

1314.8k10](/packages/webignition-absolute-url-deriver)[elegantly/laravel-cookies-consent

Cookie consent for Laravel

233.5k](/packages/elegantly-laravel-cookies-consent)

PHPackages © 2026

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