Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112575 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1250 invoked from network); 21 Dec 2020 18:07:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 21 Dec 2020 18:07:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 4FC321804B1 for ; Mon, 21 Dec 2020 09:39:52 -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=1.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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, 21 Dec 2020 09:39:51 -0800 (PST) Received: by mail-lf1-f51.google.com with SMTP id h205so25625877lfd.5 for ; Mon, 21 Dec 2020 09:39:51 -0800 (PST) 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=YkMOdGjoFjL266FAAPZvjRQI0oFsGzFjRwjVZF36MYU=; b=TEN2Okhx/I9oPXKfenOrirAlW3LIb3b+P9e29Y1SR4aEwnoD3lkd24t9YcJaCKBv4M xOL8+ncWonYEpHuJOtk3EmzDdZLvU6Gr1izzOfdkGkQoAvMVUOJSlAKQsE89HPiw1KFM auyzuy8zD9h7gLtz/0ZrAF5hg2+XiLkgIz+PL+351ryOcLxvALsEBFx0hiMYkkhQu9Je NgX1MERECvfAD481Pqo4Ya5OxuBWqJsxl7Jc4mD8cnM4bl3l8BVDC6S/G7GtEUnBfTx/ P1uYKOwR1nMIoPu21YqADowZ5sGqXJ7OSa7f4f6nxc2/4A1YhGd3OJsFld4eHC3jxe1U QG2w== X-Gm-Message-State: AOAM5310RepPM84pmC9LWlZyqPitVwyDQNRTisUkjGT7QJsPcCjb2OXr 8RW4t27levGe7Z0UWjeSaWmjvHhMPyvw9EapAXm/rw== X-Google-Smtp-Source: ABdhPJw7JgQeSRqibuIlLd9bsJodC/00wYsxFZ32kDAouEmTBjCTy5eHi8Nilcf0E0cigjff1LDLpA8xfqhCc0bsOPc= X-Received: by 2002:a19:5f5d:: with SMTP id a29mr6790308lfj.212.1608572390123; Mon, 21 Dec 2020 09:39:50 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 21 Dec 2020 11:39:39 -0600 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000e8c39905b6fcf197" Subject: Re: [PHP-DEV] Straw poll: Naming for `*any()` and `*all()` on iterables From: pollita@php.net (Sara Golemon) --000000000000e8c39905b6fcf197 Content-Type: text/plain; charset="UTF-8" On Sat, Dec 19, 2020 at 2:24 PM tyson andre wrote: > I've created a straw poll for the naming pattern to use for `*any()` and > `*all()` on iterables. > https://wiki.php.net/rfc/any_all_on_iterable_straw_poll > > This is probably going to be a terrible idea because it involves a little magic but... "iterable" is already a forbidden userspace class name since it's reserved for the psuedo-type which is a union of `Traversable | array`. What if we went ahead and defined an actual (abstract-final) `iterable` class. The parser rules which treat `iterable` as a special type still apply, so we never try to match instances of class `iterable`, but what we can do is define methods on it. class Iterable { static public function any(iterable $iter, Callable $predicate): bool { ... } static public function all(iterable $iter, Callable $predicate): bool { ... } } Then the API is both 100% searchable (the man page for iterable can explain that it's a pseudo-type AND that it has helper methods), and intuitive to read/write. if (iterable::any($iter, fn($elem) => $elem === 'foo')) { } --000000000000e8c39905b6fcf197--