Download the PHP package smoren/sequence without Composer
On this page you can find all versions of the php package smoren/sequence. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download smoren/sequence
More information about smoren/sequence
Files in smoren/sequence
Informations about the package sequence
PHP Iterator-based sequences
Python-like sequences with iterators for PHP.
How to install to your project
Quick Reference
Loops
Functionality | Description | Code Snippet |
---|---|---|
Range-based for |
Python-like range-based loop | foreach(xrange($start, $size, $step) as $value) |
Sequences
Class | Description | Code Snippet |
---|---|---|
Range |
Iterable arithmetic progression | new Range($start, $size, $step) |
Exponential |
Iterable geometric progression | new Exponential($start, $size, $step) |
DynamicSequence |
Callback-configurable sequence | new DynamicSequence($start, $size, $nextValueGetter, $indexedValueGetter) |
Data containers
Class | Description | Code Snippet |
---|---|---|
IndexedArray |
Python-like indexed list | new IndexedArray($array) |
Functions
Function | Description | Code Snippet |
---|---|---|
xrange |
Creates iterable range | xrange($start, $size, $step) |
map |
Maps iterable collections and returns IndexedArray of mapped values | map($mapper, ...$collections) |
filter |
Filters iterable collection and returning IndexedArray of filtered items | filter($collection, $filter) |
reduce |
Reduces an iterable collection | reduce($collection, $reducer, $initialValue) |
Usage
Loops
Range-based for
Unlike the PHP built-in function range()
, xrange()
does not create an array, but a Traversable
object
that takes up a small amount of memory, regardless of the number of elements in the sequence.
Sequences
Range
Iterable arithmetic progression.
For infinite sequence use $size = null
.
Exponential
Iterable geometric progression.
For infinite sequence use $size = null
.
Dynamic Sequence
Implementation of sequence configured with callables.
For infinite sequence use $size = null
.
Data containers
Indexed Array
Python-like indexed list.
Its keys are always an unbroken sequence of natural numbers starting from zero.
It is also allowed to access array elements from the end with negative indices.
OutOfRangeException will be thrown when trying to access a non-existent index.
Functions
xrange
Creates iterable range.
Works like xrange()
function in python2 or range()
function in python3.
map
Maps iterable collection and creating IndexedArray of mapped values as a result.
filter
Filters iterable collection and returning IndexedArray of filtered items.
reduce
Reduces an iterable collection.
Unit testing
Standards
PHP Sequence conforms to the following standards:
- PSR-1 — Basic coding standard
- PSR-4 — Autoloader
- PSR-12 — Extended coding style guide
License
PHP Sequence is licensed under the MIT License.