Download the PHP package hadasbro/php-streams without Composer
On this page you can find all versions of the php package hadasbro/php-streams. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hadasbro/php-streams
More information about hadasbro/php-streams
Files in hadasbro/php-streams
Package php-streams
Short Description PHP Streams - Java-like Stream API for PHP
License MIT
Informations about the package php-streams
PHP Streams
This is just Collections API in PHP.
Library helps to handle collections such as arrays
or
in general iterable
elements and perform
operations on them. Operations on Collection/Stream can be chained.
See usage examples in /Examples
and unit tests in the project.
Project status: project is in progress, curent basic version is ver 1.0.4
.
Next versions will be using generators (yield
) instead of normal looping and arrays.
Install
Installation via Composer
Usage Examples
Stream usage
Init / Construct options
Example of chaned operations on stream
Sample Object
Example - arrow functions used for operations (PHP >= 7.4)
See more Arrow Functions PHP 7.4
Example - lambda functions used for operations
Raw examples, static usage - lambda functions used for operations
Example of Collections::collect
(predefined collectors)
Examples:
Predefined collectors
Example of Collections::allMatch
(all objects from our array are also in another array)
Example of Collections::distinct
(get only objects with different IDs)
Example of Collections::filter
(get only objects with the ID < 11)
Example of Collections::reject
(remove objects with ID < 11)
Example of Collections::map
, Collections::transform
(modify every objeect's ID to be + 100)
Example of Collections::minMax
(get object with the lowest ID)
Example of Collections::sort (sort collection of objects to start from objects with the lowest ID)
Example of Collections::orElse
(get collection with objects but replace each one with ID <= 0 to default one)
Example of Collections::reduce (reduce array of objects info arrayof their a bit modified IDs)
Example of Collections::groupBy
(group objects by type)
Example of Collections::countBy
and Collections::count
(group objects by type)
Example of Collections::contains
and Collections::search
(search elements in a collection or just check if collection contains element)
Example of Collections::forEach
(consuming collection's elements)
Example of Collections::toAssocArray
(transform collection to associative array of elements)
Other examples - Collections::isEmpty
, Collections::isNotEmpty
and others
Raw examples, static usage - arrow functions used for operations (PHP >= 7.4)
Example of Collections::allMatch
, Collections::aanyMatch
(all objects from our array are also in another array)
Example of Collections::filter
(get only objects with the ID < 11)
Example of Collections::reject
(remove objects with ID < 11)
Example of Collections::map
, Collections::transform
(modify every objeect's ID to be + 100)
Example of Collections::minMax
(get object with the lowest ID)
Example of Collections::distinct
(get only objects with different IDs)
Example of Collections::sort (sort collection of objects to start from objects with the lowest ID)
Example of Collections::orElse
(get collection with objects but replace each one with ID <= 0 to default one)
Example of Collections::reduce (reduce array of objects info arrayof their a bit modified IDs)
Example of Collections::groupBy
(group objects by type)
Example of Collections::contains
and Collections::search
(search elements in a collection or just check if collection contains element)
Example of Collections::collect
(predefined collectors)
Examples:
Contract for stream methods (non static ones)
Below interface show full contract of all stream methods can be used.
Contract for static methods
Below interface show full contract of all static methods can be used.
Informations
Curently library needs PHP >= 7.4. Soon it will be redesigned to support also older versions of PHP.
Author - Slawomir Hadas
All versions of php-streams with dependencies
ext-json Version *