PHPackages                             diephp/sequences - 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. diephp/sequences

ActiveLibrary

diephp/sequences
================

Iterator of sequences

v1.3.2(1y ago)01.2k1MITPHPPHP ^7.4 || ^8.0

Since May 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/diephp/sequences)[ Packagist](https://packagist.org/packages/diephp/sequences)[ RSS](/packages/diephp-sequences/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (9)Used By (1)

Sequences
---------

[](#sequences)

#### Infinity Iterators of sequences

[](#infinity-iterators-of-sequences)

Infinity Iterators are a powerful tool for handling endless or large sequences of data. Designed for efficiency and flexibility, these iterators allow seamless traversal and manipulation of sequences without requiring the entire sequence to be loaded into memory.

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

[](#installation)

Install the package via Composer:

```
composer require diephp/sequences
```

Or manually add it to your `composer.json`:

```
{
  "require": {
    "diephp/sequences": "^v1.3.0"
  }
}
```

### Key Features

[](#key-features)

Endless Sequences: Handle infinite sequences gracefully, making them suitable for scenarios where data is continuously generated or streamed. Lazy Evaluation: Elements are generated on-the-fly, ensuring minimal memory usage and optimized performance. Customizable: Easily define custom sequences and behaviors to fit specific needs. Composable: Combine multiple iterators to create complex data flows and transformations.

Use Cases
---------

[](#use-cases)

Data Streaming: Ideal for applications that process continuous data streams, such as live feeds or real-time analytics. Large Dataset Processing: Efficiently work with large datasets that cannot be loaded entirely into memory. Algorithm Implementation: Perfect for implementing algorithms that require infinite sequences, such as the Fibonacci sequence or prime numbers.

Example
-------

[](#example)

### ExponentialSequence

[](#exponentialsequence)

Represents an exponential sequence that implements the Iterator interface.

```
$sequence = new \DiePHP\Sequences\ExponentialSequence(1, 100);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(1)
 *  int(2)
 *  int(4)
 *  int(8)
 *  int(16)
 *  int(32)
 *  int(64)
......
 */
```

### LogarithmicSequence

[](#logarithmicsequence)

Represents a sequence where each value is computed logarithmically based on a given start value and percentage increment.

```
$sequence = new \DiePHP\Sequences\LogarithmicSequence(1000000, 100);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(1000000)
 *  int(2866747)
 *  int(8218239)
 *  int(23559615)
 *  int(67539464)
 *  int(193618581)
 *  int(555055559)
 *  int(1591204067)
 *  int(4561580082)
 *  int(13076897726)
......
 */
```

```
$sequence = new \DiePHP\Sequences\LogarithmicSequence(10, 50);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(10)
 *  int(20)
 *  int(40)
 *  int(80)
 *  int(159)
 *  int(315)
 *  int(623)
 *  int(1231)
 *  int(2432)
 *  int(4805)
......
 */
```

### ProgressiveSequence

[](#progressivesequence)

Represents a progressive sequence that can be iterated over.

```
$sequence = new \DiePHP\Sequences\ProgressiveSequence(100, 50);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(100)
 *  int(150)
 *  int(250)
 *  int(400)
 *  int(600)
 *  int(850)
 *  int(1150)
......
 */
```

### LinearSequence

[](#linearsequence)

Represents a linear sequence that implements the Iterator interface.

```
$sequence = new \DiePHP\Sequences\LinearSequence(100, 50);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(100)
 *  int(150)
 *  int(200)
 *  int(250)
 *  int(300)
 *  int(350)
 *  int(400)
......
 */
```

```
$sequence = new \DiePHP\Sequences\LinearSequence(0, 10);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(0)
 *  int(10)
 *  int(20)
 *  int(30)
 *  int(40)
......
 */
```

### FibonacciSequence

[](#fibonaccisequence)

This class generates a Fibonacci sequence, implementing the Iterator interface.

```
$sequence = new \DiePHP\Sequences\FibonacciSequence(2);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(2)
 *  int(2)
 *  int(4)
 *  int(6)
 *  int(10)
 *  int(16)
 *  int(26)
......
 */
```

### InfiniteSequence

[](#infinitesequence)

InfiniteSequence is an implementation of the Iterator interface, representing an infinite sequence of integers.

```
$sequence = new \DiePHP\Sequences\InfiniteSequence(2);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(2)
 *  int(3)
 *  int(4)
 *  int(5)
 *  int(6)
 *  int(7)
 *  int(8)
......
 */
```

### UniqSequence

[](#uniqsequence)

Represents a random sequence generator that implements the Iterator interface.

\*\*\* Guarantees uniqueness but may consume a lot of memory for large values.

```
$sequence = new \DiePHP\Sequences\UniqRandSequence(1, 100);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(34)
 *  int(20)
 *  int(75)
 *  int(88)
 *  int(4)
 *  int(72)
 *  int(98)
 *  int(21)
 *  int(9)
......
 */
```

### RandSequence

[](#randsequence)

Represents a random sequence generator that implements the Iterator interface.

\*\*\* Does not guarantee unique values.

```
$sequence = new \DiePHP\Sequences\RandSequence(1, 100);
foreach ($sequence AS $value) {
    var_dump($value);
}
/**
 *  int(2)
 *  int(58)
 *  int(51)
 *  int(55)
 *  int(60)
 *  int(54)
 *  int(51)
 *  int(50)
 *  int(55)
......
 */
```

Tests
-----

[](#tests)

```
composer test
```

Conclusion
----------

[](#conclusion)

Infinity Iterators of sequences provide a robust solution for managing and iterating over endless or large sequences of data. Their lazy evaluation and customization capabilities make them versatile for various applications, ensuring efficient and effective data handling.

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance43

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community9

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

Recently: every ~0 days

Total

8

Last Release

453d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/843845c3857f227042e7ae4ea3f5e255f8e14fc59d6a971b72bc0670996e7701?d=identicon)[diephp](/maintainers/diephp)

---

Top Contributors

[![AnatolyAstapov](https://avatars.githubusercontent.com/u/12308843?v=4)](https://github.com/AnatolyAstapov "AnatolyAstapov (14 commits)")

---

Tags

iteratorsequences

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/diephp-sequences/health.svg)

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

###  Alternatives

[phpunit/php-file-iterator

FilterIterator implementation that filters files based on a list of suffixes.

7.5k879.3M72](/packages/phpunit-php-file-iterator)[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)[dusank/knapsack

Collection library for PHP

5351.0M25](/packages/dusank-knapsack)[athari/yalinqo

YaLinqo, a LINQ-to-objects library for PHP

4561.2M5](/packages/athari-yalinqo)[amphp/pipeline

Asynchronous iterators and operators.

7632.7M34](/packages/amphp-pipeline)

PHPackages © 2026

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