ArrayObject Stream API

From: Date: Tue, 03 Jan 2017 10:23:20 +0000
Subject: ArrayObject Stream API
Groups: php.internals 
Request: Send a blank email to internals+get-97504@lists.php.net to get a copy of this message
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

« previous php.internals (#97504) next »