Re: [PHP-DEV] List comprehensions and generator expressions for PHP

2012-06-28 Thread David Muir
On 28/06/12 23:45, Sebastian Krebs wrote: > Hi, > > 2012/6/28 David Muir > >> I'd assume that array_map() only works with arrays, while list >> comprehension should work with anything traversable. >> > That sounds more like a "bug" (better: "Missing feature") in array_map() > and less a missing la

Re: [PHP-DEV] List comprehensions and generator expressions for PHP

2012-06-28 Thread Nikita Popov
> No mention of yielding keys in the comprehensions. Presume that would > work? Yup, that works too. I also included an example in the mail: $firstNames = [foreach ($users as $user) yield $user->id => $user->firstName]; This creates a map from ids to first names. > The simplest example I cou

Re: [PHP-DEV] List comprehensions and generator expressions for PHP

2012-06-28 Thread Nikita Popov
On Thu, Jun 28, 2012 at 2:43 PM, Sebastian Krebs wrote: > Hi, > > Whats the difference to the (already existing) function array_map() (except > the syntax and one more new keyword)? > >> $firstNames = array_map(function($user){return $user->firstname;}, > $users); > > Don't want to rewrite every e

Re: [PHP-DEV] List comprehensions and generator expressions for PHP

2012-06-28 Thread Sebastian Krebs
Hi, 2012/6/28 David Muir > I'd assume that array_map() only works with arrays, while list > comprehension should work with anything traversable. > That sounds more like a "bug" (better: "Missing feature") in array_map() and less a missing language feature... Regards, Sebastian > > David >

RE: [PHP-DEV] List comprehensions and generator expressions for PHP

2012-06-28 Thread Jared Williams
> -Original Message- > From: Nikita Popov [mailto:nikita@gmail.com] > Sent: 28 June 2012 11:49 > To: PHP internals > Subject: [PHP-DEV] List comprehensions and generator > expressions for PHP > > Hi internals! > > Python and several other languages include support for list > comp

Re: [PHP-DEV] List comprehensions and generator expressions for PHP

2012-06-28 Thread David Muir
I'd assume that array_map() only works with arrays, while list comprehension should work with anything traversable. David On 28/06/2012, at 10:43 PM, Sebastian Krebs wrote: > Hi, > > Whats the difference to the (already existing) function array_map() (except > the syntax and one more new key

Re: [PHP-DEV] List comprehensions and generator expressions for PHP

2012-06-28 Thread Sebastian Krebs
Hi, Whats the difference to the (already existing) function array_map() (except the syntax and one more new keyword)? > $firstNames = array_map(function($user){return $user->firstname;}, $users); Don't want to rewrite every example you gave, but you probably see my point. Regards, Sebastian 20

Re: [PHP-DEV] List comprehensions and generator expressions for PHP

2012-06-28 Thread Jordi Boggiano
Heya, > So, what do you think? Do we want something like this in PHP? I think it looks great, especially the generator functions would be useful to avoid having to create a full blown iterator for simple stuff. Cheers -- Jordi Boggiano @seldaek - http://nelm.io/jordi -- PHP Internals - PHP