Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98582 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77693 invoked from network); 18 Mar 2017 01:58:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Mar 2017 01:58:01 -0000 Authentication-Results: pb1.pair.com header.from=php@golemon.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=php@golemon.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain golemon.com does not designate 209.85.128.195 as permitted sender) X-PHP-List-Original-Sender: php@golemon.com X-Host-Fingerprint: 209.85.128.195 mail-wr0-f195.google.com Received: from [209.85.128.195] ([209.85.128.195:36752] helo=mail-wr0-f195.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 79/CA-38004-9249CC85 for ; Fri, 17 Mar 2017 20:58:01 -0500 Received: by mail-wr0-f195.google.com with SMTP id l37so11321494wrc.3 for ; Fri, 17 Mar 2017 18:58:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=golemon-com.20150623.gappssmtp.com; s=20150623; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=dYNdKvuLSoChmOCuxvi94ncmKQRbHh3WAZ0VdSlo7N4=; b=YU0XFDKG9UqD3R4hQfU5JlOC6+qFGfvtVZLOC5bhOIn9+vmKrvti94lE4JFEGnvpDp pMQwxw6BeZLeX56I/e527sMz6EqtQVx3V0gaVC9EsYCS0/PIcv+HGzyLptoTrlWGrFz4 WGe1eymP+kqtAaGcip208uxztmu9LNr52r/a2I0mKI+5me1Fx7MTLE63Y27CyFpQgf5v YBslSyPfSWTN5rO8Z9yxTYATeQuFmmU5XoKLNxw5huSSFfyao5tSQHrN/9Wo7nGBdyRK s6vS+rqFy/OSAdGaD3fSJUOdZlNAGPQ+IJ2WUIw0rGHKd0D0he6QUBrIriKJWbXvZPe+ V1Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=dYNdKvuLSoChmOCuxvi94ncmKQRbHh3WAZ0VdSlo7N4=; b=DMicYrmVr+yzTOH57L55/sG4KVpar/bJvxDvwB+524t/Uo2gzxmhOCgeSlXUeHFBGy GmZD2Nv9IvTwfEr+9HFPPVGGu3cBVDA8hgJY5Hp24VB7UZfIZffJVBBMehje/4273+ro +HnH6xLfYn+xOYumm0y9GB6Nisxn+GHWcRk8Ogyi/6Ax1yGfw5Sb+gd01dgDXc0mimKG dG33X26j6W1VBHXgLmkItYCMHN0MvLQs2Ygq55KCr1A31d9h+iqK8x+rWWj5lmbjESWo q1XRMVyQM94Bqyui7P3rPyWF5hTUFtXaXkmNyO5m9rn95MY41K6GoN9L/sNNTUNtytaX CUcg== X-Gm-Message-State: AFeK/H1L9Kp0auhjkik91cpTfjX2fflmUasjF/KlXBLfXDHX5W8dBKpghm59Q5/sM0tmLL42rEHBxVAuAABS9g== X-Received: by 10.223.128.34 with SMTP id 31mr10663062wrk.179.1489802278566; Fri, 17 Mar 2017 18:57:58 -0700 (PDT) MIME-Version: 1.0 Sender: php@golemon.com Received: by 10.223.152.213 with HTTP; Fri, 17 Mar 2017 18:57:58 -0700 (PDT) X-Originating-IP: [73.9.224.155] In-Reply-To: References: Date: Fri, 17 Mar 2017 20:57:58 -0500 X-Google-Sender-Auth: -R71Yk4kB8qJlnnN9MKR1llol34 Message-ID: To: David Rodrigues Cc: Niklas Keller , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Let range() return a generator? From: pollita@php.net (Sara Golemon) On Fri, Mar 17, 2017 at 8:40 PM, David Rodrigues wrote: > There are some way to PHP be flagged before run some function, and > understand that you wants to return a Generator instead of array? > For instance: new Generator(range(1, 1000)) makes range() work like a > generator instead of return an array - it's an alternative to avoid new > keywords. > Or, maybe, some side implementation like Generator::range(1, 1000), > Generator::array_values($array), etc. (Currently, for instance, we can > simulate the range() Generator, but not array_values()) > Why would array_values() as a generator be difficult? function generate_values(Traversable $in) { foreach ($in as $k => $v) { yield $k => $v; } } In general, your `new Generator($arr)` concept misses most of the usefulness of using a generator since arrays are already traversable, and you've already allocated all the space of a full container. Where's the benefit from making it a generator? -Sara