2017 © Pedro PelĂĄez
 

library phpstream

PHPStream claims to be a partial PHP port of the Java Stream API.

image

hguenot/phpstream

PHPStream claims to be a partial PHP port of the Java Stream API.

  • Thursday, June 14, 2018
  • by hguenot
  • Repository
  • 1 Watchers
  • 6 Stars
  • 120 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 9 % Grown

The README.md

PHP Stream

PHP Stream is a basic port of new Java Stream API in PHP., (*1)

This library could be used to filter, convert or reduce any array., (*2)

Continuous integration

Build Status Code coverage GitHub last version Packagist last version Packagist downloads, (*3)

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

php composer.phar require --prefer-dist hguenot/phpstream "*"

or add, (*6)

"hguenot/phpstream": "*"

to the require section of your composer.json file., (*7)

Usage

  • Here is a basic usage of this library.
// Create a simple array of data
$array = [ -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ];

// Creates a Stream based on the previous array
$stream = new \phpstream\Stream($array);

// Compute the opposite value of each value
$stream = $stream->map(function($value){
    return intval($value) * (-1);
});

// Get only odd values
$stream = $stream->filter(function($value){
    return (intval($value) % 2) == 0;
});

// Collects data into an array
$new_array = $stream->collect(new \phpstream\collectors\ListCollector());

// Computes sum of all elements
$sum = $stream->reduce(function($a, $b){
    return intval($a) + intval($b);
}, 0);
  • All stream operations can be chained :
$sum = \phpstream\Stream::of($array)
    ->map(function($value){
        return intval($value) * (-1);
    })
    ->filter(function($value){
        return (intval($value) % 2) == 0;
    })
    ->reduce(function($a, $b){
        return intval($a) + intval($b);
    }, 0);

You can find more examples on PHPUnit test., (*8)

The Versions

14/06 2018

dev-master

9999999-dev

PHPStream claims to be a partial PHP port of the Java Stream API.

  Sources   Download

MIT

by Hervé Guenot

stream java stream api

14/06 2018

v1.3.0

1.3.0.0

PHPStream claims to be a partial PHP port of the Java Stream API.

  Sources   Download

MIT

by Hervé Guenot

stream java stream api

25/02 2018

v1.2.0

1.2.0.0

PHPStream claims to be a partial PHP port of the Java Stream API.

  Sources   Download

MIT

by Hervé Guenot

stream java stream api

19/02 2018

v1.1.0

1.1.0.0

PHPStream claims to be a partial PHP port of the Java Stream API.

  Sources   Download

MIT

by Hervé Guenot

stream java stream api

22/09 2015

v1.0

1.0.0.0

PHPStream claims to be a partial PHP port of the Java Stream API.

  Sources   Download

MIT

by Hervé Guenot

stream java stream api