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
> 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
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
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
>
> -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 lang
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
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
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
Hi internals!
Python and several other languages include support for list
comprehensions and generator expressions and I'd like to see something
similar in PHP too.
I created a hacky proof of concept implementation here:
https://github.com/nikic/php-src/tree/addListComprehensions. It's
really dir