Hi Ionut 2008/10/28 Ionut Gabriel Stan <[EMAIL PROTECTED]>: > While we're at this and considering the new lambdas that we now have in the > language > I must say I'd like some functions to support Traversables. Those would be: > > array_map(), array_reduce(), array_filter(), array_walk() and > array_walk_recursive() > > Although I'd rather want a class (because the array_* functions don't adhere > to some strict param order standards) > to provide functional style methods, like those in Javascript 1.8: > > https://developer.mozilla.org/index.php?title=En/New_in_JavaScript_1.6#section_2 > https://developer.mozilla.org/index.php?title=En/New_in_JavaScript_1.8#section_4 > > Array.forEach() > Array.map() > Array.filter() > Array.reduce() > Array.reduceRight() > Array.some() > Array.every() > > > In PHP something like this would be nice: > > $processedDirectoryIterator = SplFunctional(new > DirecotoryIterator(__DIR__)).map(function() { > // do stuff here > });
This would indeed be nice, but theres one thing yet, PHP doesn't support closure objects, take for example: <?php class Test { public function hello($who) { echo 'Hello ' . $who; } } $closure = function() { static $instance; if(!$instance) { $instance = new Test; } return($instance); }; $closure->hello('Kalle'); // Fatal error, undefined method Closure::hello() But you should indeed make an RFC for this and even create a patch if you're able to :) > > where SplFunctional is a function returning a SplFunctional object whose > construcor accepts iteratable > structures (arrays or Traversables) and $processDirectoryIterator is a > DirectoryIterator resulted after applying > the lamba to each of the SplFileObjects contained. > > I know right now we have FilterIterator as an equivalent to array_filter() > for Iterators and we could implement our > own Functional classes but that means a new class for situations where a > simple lambda could do the job > just as well. > > I hope my proposal makes sense. > > > P.S. I introduced a SplFunctional function just to skip the instantiation of > the object. > > > > On 10/28/2008 15:16, Lars Strojny wrote: >> >> Hi Andrei, >> >> Am Montag, den 27.10.2008, 11:34 -0700 schrieb Andrei Zmievski: >> [...] >> >>> >>> I would say "no" for 5.3. But for 6 it would be fantastic to have all >>> array-related >>> operations supporting ArrayAccess interface, where possible. >>> >> >> +1 for this. >> >> cu, Lars >> > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Kalle Sommer Nielsen -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php