PHPackages                             capci/stream - 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. capci/stream

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

capci/stream
============

Java-like Stream API library for PHP

v1.0.0(7y ago)05MITPHPPHP &gt;=7.2.0

Since Oct 14Pushed 7y agoCompare

[ Source](https://github.com/capci/Stream)[ Packagist](https://packagist.org/packages/capci/stream)[ Docs](https://github.com/capci/Stream)[ RSS](/packages/capci-stream/feed)WikiDiscussions master Synced 4d ago

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

Stream
======

[](#stream)

[![Build Status](https://camo.githubusercontent.com/7ad961ee0a5a0fdc303bdf8dfc4d0ec0a19f2b6df3945f5a9d1dfeb4e95eecee/68747470733a2f2f7472617669732d63692e6f72672f63617063692f53747265616d2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/capci/Stream)

Java-like Stream API library for PHP.

Intermediate operations are not evaluated until terminal operation is invoked (lazy evaluation).

Requires PHP 7.2 or newer.

Usage
-----

[](#usage)

Basic usage.

```
Stream::of("a", "b", "c", "d", "e", "x")->filter(function ($value) {
    return $value !== "x";
})->map(function($value) {
    return strtoupper($value);
})->forEach(function ($value) {
    echo $value . ", ";
});
// A, B, C, D, E,
```

### Generate Stream

[](#generate-stream)

- from values.

```
$stream = Stream::of("a", "b", "c");
```

- from array or Traversable.

```
$stream = Stream::ofIterable([
    "a",
    "b",
    "c",
]);
```

```
$stream = Stream::ofIterable(new DirectoryIterator("."));
```

- from generator function.

```
$stream = Stream::ofGenerator(function () {
    yield "a";
    yield "b";
    yield "c";
});
```

- and others

empty, concat.

### Intermediate operation

[](#intermediate-operation)

- filter

```
$stream = Stream::ofIterable(range(0, 10));
$stream = $stream->filter(function ($value) {
    return $value > 5;
});
// 6 7 8 9 10
```

- map

```
$stream = Stream::ofIterable(range(0, 5));
$stream = $stream->map(function ($value) {
    return $value * 2;
});
// 0 2 4 6 8 10
```

- sorted

```
$stream = Stream::ofIterable(range(0, 5));
$stream = $stream->sorted(function ($value1, $value2) {
    return $value2 - $value1;
});
// 5 4 3 2 1 0
```

- and others

flatMap, skip, skipWhile, limit, limitWhile, distinct, peek.

### Terminal operation

[](#terminal-operation)

- forEach

```
$stream = Stream::ofIterable(range(0, 5));
$stream->forEach(function ($value) {
    echo $value . ", ";
});
// 0, 1, 2, 3, 4, 5,
```

- toArray

```
$stream = Stream::ofIterable(range(0, 5));
$array = $stream->toArray();
// [0, 1, 2, 3, 4, 5]
```

- reduce

```
$stream = Stream::ofIterable(range(0, 5));
$sum = $stream->reduce(0, function ($accum, $value) {
    return $accum + $value;
});
// 15
```

- and others

count, allMatch, anyMatch, nonMatch, findFirstOrDefault, findLastOrDefault, maxOrDefault, minOrDefault.

License
-------

[](#license)

MIT

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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

2771d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21971116?v=4)[capci](/maintainers/capci)[@capci](https://github.com/capci)

---

Tags

phpstream-apiStream API

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/capci-stream/health.svg)

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

PHPackages © 2026

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