Streams is a port of the Streams library for PHP. It makes working with collections super pleasant.
An example with the Yii ActiveRecord lib:
<?php
use Streams as S;
$collection = Car::model()->findAll(); // Returns an array of Car objects
$carStream = new S\Stream($collection);
$newCollection = $carStream
->filter(function( $car ) {
return ($car->price > 36000); // return only expensive cars!
})->map(function( $car ) {
$car->setCo2EmissionTaxes(20); // Since is an expensive car, lets make the people who drive it more poor :D
return $car;
})->getElements();
Even though this library is under active development, the currently available methods are:
###map(callable $callback) As in every functional programming language, map takes a function as argument and applies it to each element in the array, returning a new array with the results.
###filter(callable $callback) takes a function as argument and applies it to each element in the collection. It returns a new collection containing all elements where the callback returned true.