Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61030 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72015 invoked from network); 28 Jun 2012 17:28:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Jun 2012 17:28:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:52492] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 18/A1-62543-8549CEF4 for ; Thu, 28 Jun 2012 13:28:57 -0400 Received: by lbgc1 with SMTP id c1so3830900lbg.29 for ; Thu, 28 Jun 2012 10:28:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=2gz2Xa/JLyIL/CX+sJCNN+U92hCpkl37/N/GXbcoFCc=; b=YL+nqo0zRx65LEKqVBypn98QHz4ARjC9+J7+hUaNjpfnOaPfF072IqkusY3Rfs4DQ+ e9MHXrN4jpv0wWsLyvrO/f4OMfZslcdhJxJn32LV1f6Eqgrqv4AP0o+mxcxlovHQWY7h uwPZDTXzLPA3v+yJeEka7tiu89aBetZiBz/6ujSdgqMbV6Epm+AQC1FP0LFm77NztTv6 Wp1UdauS4WM42XR9meNWcpb8AFMYem4EcvHJEPtyBWzpDu4G39XjD3S5F6aJshHYmVm4 j0++s/6HPicBlijVafj06v4ZgdB7EvsWXAFRldXRFfCHNLETCONgKtldrq1rxm6/GcTp cvpg== MIME-Version: 1.0 Received: by 10.112.104.100 with SMTP id gd4mr1553263lbb.24.1340904533660; Thu, 28 Jun 2012 10:28:53 -0700 (PDT) Received: by 10.152.114.70 with HTTP; Thu, 28 Jun 2012 10:28:53 -0700 (PDT) In-Reply-To: <20120628132301.VGUS3795.aamtaout02-winn.ispmail.ntl.com@p2> References: <20120628132301.VGUS3795.aamtaout02-winn.ispmail.ntl.com@p2> Date: Thu, 28 Jun 2012 19:28:53 +0200 Message-ID: To: Jared Williams Cc: PHP internals Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] List comprehensions and generator expressions for PHP From: nikita.ppv@gmail.com (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 =3D [foreach ($users as $user) yield $user->id =3D> $user->firstName]; This creates a map from ids to first names. > The simplest example I could think of using Memcached > (assuming libmemcached fetch() does return as soon as it recieves an > item) > > Eg. > > function *getMulti(Memcached $memcached, array $keys) > { > =A0 =A0if ($memcached->getDelayed($keys)) { > =A0 =A0 =A0 =A0while ($item =3D $memcached->fetch()) > =A0 =A0 =A0 =A0 =A0yield $item['key'] =3D> $item['value']; > =A0 =A0} > } > > foreach(getMulti($memcached, ['foo', 'bar', ... ]) as $key =3D> $value) > { > =A0 =A0 =A0 =A0doSomeWork(); > } > > So doSomeWork would be called as soon as a single value is available, > rather > than having to wait til all values have returned. > > Should in theory work right? Yup, that should work :) Nikita