Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112834 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47604 invoked from network); 10 Jan 2021 19:30:08 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 10 Jan 2021 19:30:08 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A90BA1804D3 for ; Sun, 10 Jan 2021 11:07:39 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sun, 10 Jan 2021 11:07:39 -0800 (PST) Received: by mail-io1-f52.google.com with SMTP id q1so1105865ion.8 for ; Sun, 10 Jan 2021 11:07:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yvAVkTm80mdh1S2P3NS2HQkHOxm5sTnJl7l4FfmC9Rs=; b=ETXnlTA92FymjCZuZ5g/Ee4mj5YfW4uAxXFPsAyLIW59iNJJz0JHozHkSyaYarexit lmhoEjgdGDbQJhHR7HjMUtBd1oiqUfss9Cqf/WCFN4ZhxFZvINaMwgATqSR+X67Vxtgt k5KgxjrczT/RBC3wWLlCoMa5oTjev/pVy+R8Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yvAVkTm80mdh1S2P3NS2HQkHOxm5sTnJl7l4FfmC9Rs=; b=hVosahQ6Okopaacw9orzdVGvXtyTF2qSQqsU3RGP8jPDvf55TITHwtzw7vsQ5iQVGs OBe5zvxeEDPZdv5S4WR2LJjX0A65iR4kuLv2y5UjdiE7WuyIjCxcNOwy1D6upy+t5r6Y ByjFs4o50napzjG2kdys4YKOV02kx/BrOWbX0ll0Qq1kJk1bx0iAmj064quw4kAEI6B3 b00bCyZQsAraY7QTdTc6qYc+UZ1a8rLmK6JtIPFxKKDUAVjegUi6tAAeraGrk8446M1T xlnKmEUBBvkmiqrs4iffi12qF/DbNEtcEqL6rHvilXHL0ZLrhl/ZlS+W0KQ3gjTTjZjf pEmg== X-Gm-Message-State: AOAM533Fd1xIo/w5dMvbeaos7UcYmATW3J7tvTCRMGDOUJPWV/V9krJ1 4to+ngnio9WXHI5CyKSizr8EPRSLdO5AGzktpy9IwA== X-Google-Smtp-Source: ABdhPJyNPopX5ce3V3gXw7j3htIVUaPES97q4DSmHPQT4UUWDB2KLs4Bvhir1y18Id1KOEOyHokfnBu71TA56DcR5uA= X-Received: by 2002:a6b:8e92:: with SMTP id q140mr12507296iod.182.1610305657577; Sun, 10 Jan 2021 11:07:37 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Reply-To: Levi Morrison Date: Sun, 10 Jan 2021 12:07:26 -0700 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Re: Straw poll: Naming for `*any()` and `*all()` on iterables From: internals@lists.php.net ("Levi Morrison via internals") I want to make a case for `Spl`. Aside from autoloading (which really ought to be in core but since "spl" is literally in the name of those functions it's kind of stuck), the SPL is mostly data structures and iterator related functionality. It makes perfect sense to me that iterator related behavior like these iterable functions being proposed should be included in the SPL. The `Spl` namespace is short, and its brevity doesn't lose any meaning because the SPL has been around in core since PHP 5.3 (I think?). I do think we need to propose at least a few more things at the same time to help set the correct patterns and precedent. I'm leaving off the namespace here: Variants on what is already proposed: - any_value(iterable $of, callable $satisfies) - all_values(iterable $of, callable $satisfy) These are iterable primitives to implement many other routines: - reduce_values(iterable $of, callable $by) // throws if there isn't at least 1 value - fold_values(iterable $of, $withInitial, callable $by) // like reduce but doesn't throw since it can use an initial - to_iterator(iterable): Iterator // to be able to write the previous two functions in a generic way New iterators (I have a patch for the first one: https://github.com/morrisonlevi/php-src/tree/spl/ForwardArrayIterator) - ForwardArrayIterator // to have an efficient iterator for Array (ArrayIterator nearly always duplicates the array) - ReverseArrayIterator // long overdue Less certain on these specific names but this functionality is common: - values(iterable $of): iterable // only returns values (does not fetch keys at all) - keys(iterable $of): iterable // returns the keys as values (does not fetch values at all) Some common ones like map and filter have a bit more nuance because ----- One of the arguments against using the SPL is that much of its existing design is... well, weird and sub-optimal in many cases. At least a few people recommend against using SPL data structures and iterators because of this. However, I think the `Spl` namespace can separate these well enough.