Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111728 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 91152 invoked from network); 30 Aug 2020 18:44:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Aug 2020 18:44:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 118C91804AA for ; Sun, 30 Aug 2020 10:48:40 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, 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-f43.google.com (mail-io1-f43.google.com [209.85.166.43]) (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, 30 Aug 2020 10:48:36 -0700 (PDT) Received: by mail-io1-f43.google.com with SMTP id g128so3750781iof.11 for ; Sun, 30 Aug 2020 10:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Gw0QH4q2Huyx9vf3Cme/zpMrNjURkhPPR2naFYJvikA=; b=s1ieUR3wNvd104d86iviOHIFujDh6asbERb3FnLVMqAvET5IeOcIcdecsoJK2RP4ug fsAvJevBTQFIseqWV2URhSVMwg91LoIsBQ6GT2KIizbYDY2A4OLM9PfwgrEmb3z66qF2 pVwKtkz7x14EqIt3+8+3TO4cTr/V3G4qhbrAKowk4euBvZO6Xlkk1o36BS1DKSAAtoE1 aH8EXmzHNxhUOlW5vfVydByEuuF0mTBjuyg9CJdwny+FLg6F6QWH7w8S5o5VxIarIrrA xUvnhRA2rxHVwkHf0wap7kSjXGZVlOWsiqAN1QLSkXpIYi12ow3N6ZRt+H6FRVKlA7BJ Uu2A== 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=Gw0QH4q2Huyx9vf3Cme/zpMrNjURkhPPR2naFYJvikA=; b=MV650FIPOfIECIwlatHUSqOTqYqiFco1GbLfTXxLkWKiHopeAnmpZBFVlZakIaPHco idoH7acMbtDpslNAMOmRgBmRNpvtRA/f3jCjCAERMQ9hirKSGuSJqpJl7cR63QyQdse3 O06nWtoWrifG0EPf4I/M6JdaoWKVzKG6ylxzUcmJHlTtirxU59AYAIrAcwYVapFeqyBR 34n1aB07kQvZKa+bBw09YG/jcPQb6cJFn/4tPPhxn+Bj8IgDQH5YlmABrXMhzd7eVDTy cpv1aJzenSyReZD9u2sSFf5cyV/KHhxyjc61LUQZwknpEbFJiEbCRMn/+5KAP14eukFy /7HQ== X-Gm-Message-State: AOAM5333ONINf+ZvgUmdggcU3mp97sbJtsTnoJznBuIQxJFj1OE7LyIs nF13IyQDVykEAH3tu05vmtoBB/DT8H1yv80r7KE= X-Google-Smtp-Source: ABdhPJzlJDYHnsUpUSRuILD2OlLZqsNqdW3vtAk17k2s2N2vPIQCAcDNJOEZ6Vf4OTPDFmkaEX+tzriky02FrXPhfv8= X-Received: by 2002:a02:c8c6:: with SMTP id q6mr8725987jao.76.1598809713740; Sun, 30 Aug 2020 10:48:33 -0700 (PDT) MIME-Version: 1.0 References: <7d91bd8f-9ca0-4e62-886b-f89bc8edd3e9@www.fastmail.com> In-Reply-To: Date: Sun, 30 Aug 2020 20:48:22 +0300 Message-ID: To: tyson andre Cc: Larry Garfield , PHP internals Content-Type: multipart/alternative; boundary="0000000000000d100805ae1be567" Subject: Re: [PHP-DEV] Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) From: weirdan@gmail.com (Bruce Weirdan) --0000000000000d100805ae1be567 Content-Type: text/plain; charset="UTF-8" On Sun, Aug 30, 2020 at 6:13 PM tyson andre wrote: > > I like this, but I do not like the flags. I don't think they're at all > useful. A lot of the other discussion in the thread seems to be needlessly > complicating it, too. > > > > all() and any() only need return booleans. Their callbacks only need > return booleans. That's the point. first() makes sense to add, and it > would return the first value that matches. > > What would first() return on failure? Would it throw (inefficient)? > Would it set an optional output reference to distinguish between returning > the value null from an iterable and the null from no matches? > If it took the default value as well it could return that. While it's useful in itself it also would enable you to pass a marker object and check the identity of that to know if no matches have been found: $none = new stdClass; $element = first($collection, fn($elt) => ...); if ($element === $none) { // nothing found } -- Best regards, Bruce Weirdan mailto: weirdan@gmail.com --0000000000000d100805ae1be567--