Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104810 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 48462 invoked from network); 20 Mar 2019 01:40:08 -0000 Received: from unknown (HELO mail-wr1-f52.google.com) (209.85.221.52) by pb1.pair.com with SMTP; 20 Mar 2019 01:40:08 -0000 Received: by mail-wr1-f52.google.com with SMTP id w2so571190wrt.11 for ; Tue, 19 Mar 2019 15:31:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=XcSC7+pi+hSYNnSp6uPicpU4+UEh4mbWSKXFuZZ1Ku4=; b=NOYTIPY4oHw1zBWnMLEe343CJzS7lxc6EdMUwKclsF6TosaHX41iJ0Wh6WeF+kxBrC wG4tB2fYHXK4VzuVUTfS+911nq1BVQQX3gU1uzS2ievY4uE7LLtevnLXqQiJ6n3CLMsd u6zbjN1lE6ZMLUNtDGBQwxBCz5vXrBG1q+KXhaPvJ299N9TJf22qR3f+xEljTWicLV8W EcWBwX36tCTLBRc0/1E0sV8u3L7ZFl5XaBoBb/m6Bo5yAibUtI90/biL9uqr/NQHhQ3J o+bzTzg5WVphUJHGAA8JBC3PM5kk27a/jezBtE0H+JjVQikEUHyAoDiwYdFv5z0lzB/0 OOUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=XcSC7+pi+hSYNnSp6uPicpU4+UEh4mbWSKXFuZZ1Ku4=; b=f2d0jsIlqBaeo68wGuQCrXZz00QOWfH/XrCrfw1YuthJy3hXQ9P9/+k3XnTgPiytHD gwaS7c2iY+n0K5MN3CstyDeP3Dzyw3nLU/8tiWRZQgMyokPvmRhqkdoae+oS3tZrtZc0 FitT0tC1I+aPlAQc1ZsjcCEZdV9yAdpZbf6U4fDonGJJMT+EczjDYkAZ5UX3D5KET4Jk 7+1ZQHoMsWtYgYVg6GX/OztphpsAcpx8/gr0F1EmMHX4vKS5jc6g/vV4MiAgJIAz4Ucc KGgI3k4JYknTQ8pBfNsekwF3sS+3M7tjN08K7MrrUHoCI/Gm5iP/OaPzwsQkMK7GFLq8 zBXg== X-Gm-Message-State: APjAAAUtT86a30Q3yBuVG6T/ENk2auGes6fZ4zHnd7WzhL0ITR+zaTzr KJTZU0P1YGkrzatAxOcHQVbECERv X-Google-Smtp-Source: APXvYqzM7sO1UjvFflsCN5iWCOyZD9OcGZKnWfhTUV0HpRPdu+UL4iKegx5LlcJlrn+F+vHNNw7ndA== X-Received: by 2002:adf:f80c:: with SMTP id s12mr3859084wrp.72.1553034712134; Tue, 19 Mar 2019 15:31:52 -0700 (PDT) Received: from [192.168.0.16] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id o20sm236219wmh.21.2019.03.19.15.31.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Mar 2019 15:31:51 -0700 (PDT) To: internals@lists.php.net References: Message-ID: Date: Tue, 19 Mar 2019 22:31:51 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.5.3 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] RFC Draft: Comprehensions From: rowan.collins@gmail.com (Rowan Collins) On 19/03/2019 20:24, Levi Morrison wrote: > Today in the Dart world, Bob Nystrom published an article called > [Making Dart a Better Language for UI][1]. I think it's an incredibly > relevant article, since it is essentially about comprehensions, why > they are a thing, as well as some of the design choices they made. > > I think everyone in this thread ought to spend the 10-15 minutes reading it. > > [1]: https://medium.com/dartlang/making-dart-a-better-language-for-ui-f1ccaf9f546c > Hi Levi, That is indeed a very interesting article, thanks for sharing. The idea of foreach and if just being available whenever you're specifying an array is a really interesting version of this construct. The mention of the spread operator has actually given me a different idea, related to iterator_to_array. What if the "..." operator could spread any iterable, not just arrays as currently proposed in an RFC [1]? $iterator = new SomethingIterator; $array = [ ...$iterator ]; $array2 = [ ...someGenerator() ]; That plus the current comprehension proposal would give us this: $array = [ ...[ foreach $list as $x if $x % 2 yield $x*2] ]; Which could fairly naturally be special cased to this: $array = [ ... foreach $list as $x if $x % 2 yield $x*2 ]; This would give us concise syntax for both iterator and array forms, in a way that fits the rest of the language better than () vs []. [1]: https://wiki.php.net/rfc/spread_operator_for_array -- Rowan Collins [IMSoP]