ArrayObject Stream API

php.internals

Silvio Marijić

9 years ago
Hi, Happy new year to everyone. I would like feedback on idea to add stream api to ArrayObject, something like array_map and array_filter. Consider following example $students = new ArrayObject(); //... $bestStudents = new ArrayObject(); foreach($students as $student){ if ($student->grade() > 4) { $bestStudents[] = $student; } } And example with Stream API. $bestStudents = $students->filter( function($student){ if ($student->grade() > 4) return true; } )->map( function($student) { return "{$student->firstName()} {$student->lastName()}"; } ); I gave example only with map() and filter(), but there are also couple of others functions which could end up here. Cheers,
-- Silvio Marijić Software Engineer 2e Systems