Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112752 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 18278 invoked from network); 4 Jan 2021 17:51:57 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Jan 2021 17:51:57 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 460D51804E2 for ; Mon, 4 Jan 2021 09:27:57 -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.6 required=5.0 tests=BAYES_50,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-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) (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 ; Mon, 4 Jan 2021 09:27:56 -0800 (PST) Received: by mail-il1-f174.google.com with SMTP id 75so25964587ilv.13 for ; Mon, 04 Jan 2021 09:27:56 -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=/uJAhlN3sbplGO419hDjrtQTpUycTBTFGI/Cl9if0oc=; b=cgTMwaeahzZyRf9Nedj6zPP7ERqU/pILxg7ahIluoP6DHywaiJX3lL+JUOwj/ZQ5eA T7AlWA77dIERd77z8EuhX8XQva/cVzJkPmDK0L5S9NLQkPdFKgqp/mIk6TXFimcJ/s2S 051YfHWALxarrQALDH+ahgIAkKfuMllSxiMrg= 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=/uJAhlN3sbplGO419hDjrtQTpUycTBTFGI/Cl9if0oc=; b=Rs6QTZAdI9P5FcPgLBowj/LnWLo+lx50ALVwYFgYbOFkOP4+0DN2DkUfajRaFoKA6B ksvvO7efUzMUOeuldWdcE7//sWfbDS3vcK9XY4Ej2QfZNp2yB1VCJ0edxPFXjGC+QZUr xZIaUVpmvWTmb9DMqweZ6IrMdpZGBL4HeLMZYKRPv3O3gEtxxkQWAQ+CUwZth9TC30As KWH7yGRedvKzt31Zp5x8Iqvx2H85LcjUEKifCzq6emb/gM5+J3VP9lGjdGk9A/YX38XC B5bQ/5V9LC+9P+1pAteZN5dMcAPTUE+MzR3tlvEwIbObd66FR0VIvOWiGaK4MZRJBZKX IYOA== X-Gm-Message-State: AOAM533bvdmIcckpklkzUH7ASgS0J3v7BJCeXJAZXL6RcbNV0C8ksxmM zqEbhJiuJIhKGmZmRCYJ8n/QcJ6sDVcgtsTpkuszyQ== X-Google-Smtp-Source: ABdhPJxowYL4G/feJMiZoKaqajLXN/XE5wr5E9XVBsd4tKYeBu3CznJB/CDwKru6PEyfV1OLInGVN0QU2vWVTUDuMFs= X-Received: by 2002:a05:6e02:1311:: with SMTP id g17mr67855533ilr.223.1609781274281; Mon, 04 Jan 2021 09:27:54 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Reply-To: Levi Morrison Date: Mon, 4 Jan 2021 10:27:43 -0700 Message-ID: To: Niklas Keller Cc: tyson andre , "internals@lists.php.net" Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Straw poll: Naming for `*any()` and `*all()` on iterables From: internals@lists.php.net ("Levi Morrison via internals") On Sat, Dec 26, 2020 at 10:02 AM Niklas Keller wrote: >> >> I want to re-iterate my opinion on this discussion thread: anything >> with a prefix is a hard-no from me. Namespaces are literally designed >> for this, and I will not vote "yes" to `iter_all`, `iterable_all`, >> etc, no matter what the prefix is. Anything without a namespace is a >> no from me. >> >> I'm flexible on many other points, but not this one. It's 2020 (almost >> 2021); let's use namespaces for what they were designed for. This is a >> perfect opportunity; they work on more than just arrays so using the >> `array_` prefix for consistency doesn't apply. > > > Hey Levi, > > while I agree that namespaces were designed for this, I think `all` and `any` are too generic names, even in a namespace. > > I think Java's naming with any_match / all_match could be a good fit. I agree they are a bit generic, especially because we may need to distinguish between keys and values. For that reason I prefer `Spl\all_values` and `Spl\any_value`. We can make it read very well with named parameters if that's your thing: ``` if (all_values($input, 'is_int')) // or alternatively: if (all_values(of: $input, satisfy: 'is_int')) ``` I wouldn't put too much excitement into making highly readable English; I mention it mostly to point out that I think we should put at least a little bit of effort into parameter names for any new library additions. > If promises / futures make it into core in the future, there will be a need for an `any` / `all` function combining promises / futures. > > Maybe these should be named `array_*` and all array functions should be adjusted to work with iterators? Many of them can't work efficiently on iterables or have idiosyncrasies. I don't think this the way forward either. ----- I am hopeful we can add at least a few other functions alongside these additions to help establish good patterns for functions that work with iterables, as there are quite a few of them. At least we should add some form of `reduce`, as `any` and `all` are forms of reducers.