PHPackages                             pepijno/sphream - 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. pepijno/sphream

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

pepijno/sphream
===============

A library for using functional style streams

v0.2.0(6y ago)06AGPL-3.0-or-laterPHPPHP &gt;=7.0

Since Feb 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/pepijno/Sphream)[ Packagist](https://packagist.org/packages/pepijno/sphream)[ Docs](https://github.com/pepijno/sphream)[ RSS](/packages/pepijno-sphream/feed)WikiDiscussions master Synced yesterday

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

Sphream
=======

[](#sphream)

Sphream is a functional php library. It is inspired by Haskell Lists, Java8 Streams and underscore.js.

Sphream allows you to manipulate arrays and Traversables in a more intuitive way.

```
$integers = [ 3, -19, 9, 1, 5, 392, 29, -13, 29, -2, -4, 234999 ];
$newIntegers = Sphream\Sphream::of($integers)
    ->filter(function ($item) { return 0 < $item && $item < 10; })
    ->takeWhile(function ($item) { return $item > 1; })
    ->map(function ($item) { return $item * 100; })
    ->toArray();

// $newIntegers is equal to [ 300, 900 ]
```

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

[](#installation)

```
composer require pepijno/sphream
```

Documentation
-------------

[](#documentation)

### Creating Sphreams

[](#creating-sphreams)

#### of

[](#of)

Creates a Sphream from an array or a generator.

Using an array:

```
$array = [ 3, 5, 9 ];
$sphream = Sphream\Sphream::of($array);
// $sphream contains items 3, 5 and 9.
```

When using generators:

```
$generator = function () {
    yield 3;
    yield 5;
    yield 9;
};
$sphream = Sphream\Sphream::of($generator());
// $sphream contains items 3, 5 and 9.
```

#### mempty

[](#mempty)

Creates an empty Sphream.

```
$sphream = Sphream\Sphream::mempty();
//$sphream is empty
```

#### range

[](#range)

Creates a Sphream containing a range of integers between a start and an end. The end is not inclusive in the Sphream.

```
$sphream = Sphream\Sphream::range(6, 11);
// $sphream contains the elements 6, 7, 8, 9 and 10.
$sphream = Sphream\Sphream::range(-21, -17);
// $sphream contains the elements -21, -20, -19 and -18.
```

#### repeat

[](#repeat)

Creates a Sphrem by repeating a value a certain `N` times.

```
$sphream = Sphream\Sphream::repeat("Hello", 8);
// $sphream contains the string "Hello" 8 times.
```

#### generate

[](#generate)

Creates an infinite Sphream, the elements are generated by repeatedly executing the callback.

```
$callback = function () { return 2; };
$sphream = Sphream\Sphream::generate($callback);
// $sphream contains of an inifite amount of 2's.
```

### Checks

[](#checks)

#### isEmpty

[](#isempty)

Returns true if a Sphream is empty and false otherwise.

```
Sphream\Sphream::of([])->isEmpty(); // returns true
Sphream\Sphream::of([2])->isEmpty(); // returns false
```

#### isClosed

[](#isclosed)

Returns true if a Sphream is closed and false otherwise.

```
$sphream = Sphream\Sphream::of([1, 2]);
$sphream->isClosed(); // returns false
$sphream->toArray();
$sphream->isClosed(); // returns true
```

### Alterations

[](#alterations)

#### map

[](#map)

Applies a callback to each element of the Sphream.

```
$sphream = Sphream\Sphream::of([2, 3])
    ->map(function ($item) { return $item * 2; });
// $sphream consist of items 4 and 6.
```

#### filter

[](#filter)

Filters all elements from the Sphream for which the callback returns false.

```
$sphream = Sphream\Sphream::of([1, 2, 3, 4])
    ->filter(function ($item) { return ($item % 2) == 0; });
// $sphream contains elements 2 and 4.
```

### Selections

[](#selections)

#### take

[](#take)

Takes the first `N` items of the Sphream, discarding the rest of the Sphream.

```
$sphream = Sphream\Sphream::of([2, 4, 9, 1, 3])
    ->take(3);
// $sphream contains elements 2, 4 and 9.
```

#### drop

[](#drop)

Drops the first `N` items of the Sphream.

```
$sphream = Sphream\Sphream::of([2, 4, 9, 1, 3])
    ->drop(2);
// $sphream contains elements 9, 1 and 3.
```

#### takeWhile

[](#takewhile)

Takes elements from the Sphream as long as the callback returns true.

```
$sphream = Sphream\Sphream::of([2, 4, 9, 1, 3])
    ->takeWhile(function ($item) { return $item < 9; });
// $sphream contains elements 2 and 4.
```

#### takeWhile

[](#takewhile-1)

Drops elements from the Sphream as long as the callback returns true.

```
$sphream = Sphream\Sphream::of([2, 4, 9, 1, 3])
    ->takeWhile(function ($item) { return $item != 1; });
// $sphream contains elements 1 and 3.
```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity49

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

Every ~192 days

Total

2

Last Release

2506d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12099906?v=4)[Pepijn Overbeeke](/maintainers/pepijno)[@pepijno](https://github.com/pepijno)

---

Tags

streamphpfunctionalfunctional-programming

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pepijno-sphream/health.svg)

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

###  Alternatives

[lambdish/phunctional

λ PHP functional library

3632.1M24](/packages/lambdish-phunctional)[mpetrovich/dash

A functional programming library for PHP. Inspired by Underscore, Lodash, and Ramda.

10429.7k1](/packages/mpetrovich-dash)[markrogoyski/itertools-php

Iteration tools for PHP

14912.2k](/packages/markrogoyski-itertools-php)[chemem/bingo-functional

A simple functional programming library.

687.0k3](/packages/chemem-bingo-functional)[krak/fn

Functional library for php with proper currying

2419.0k3](/packages/krak-fn)[transprime-research/piper

PHP Pipe method execution with values from chained method executions

174.6k2](/packages/transprime-research-piper)

PHPackages © 2026

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