Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111729 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92925 invoked from network); 30 Aug 2020 18:57:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Aug 2020 18:57:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D44141804D9 for ; Sun, 30 Aug 2020 11:01:54 -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-f46.google.com (mail-io1-f46.google.com [209.85.166.46]) (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 11:01:54 -0700 (PDT) Received: by mail-io1-f46.google.com with SMTP id d18so3763912iop.13 for ; Sun, 30 Aug 2020 11:01:54 -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=kelrYlN8G3DKqjkFxpI29NYi3tfGUGC6v+xPc4aX6e0=; b=VBSz99mRyzxQ+gpNVXnOdnVN9n2+XGRTmsgklKgbvTerExMSXTOkV+yMPDDJ+WYxp2 fiNy06i4KNmqtRp6FR/DtV8GG66FtGHEgA0wpqI7yKCr+08sGthyl7n9gqXg/cpDYJtk fxMdWEJNQdoyyd3uICuvYNWuoDDxyGdVw/OeEKjqlT5oQpDeoWcqUB7x5aRdqjv6nrkb d81xF+kVGln4wiWPU37U7GhQDTfXQnI7wgWZVGiWNbjpGTL07Z6RPVqwRIcJB59I610R lItRS9oB07HXHyG2xy5NcCHSwWreJnzSZHHI2FxrALjem/lMaGhuR95DjFb1ZF4XDisr hcZA== 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=kelrYlN8G3DKqjkFxpI29NYi3tfGUGC6v+xPc4aX6e0=; b=cdkZq/PTgucNC44HBFj2hWBZaBi1FlF4OQ+nucSs+lZqXb24PVJ5B10Nb7Hog5sB+s ToL1PPZ4nH9lYPrkZyApoxcxyEO0uXfNQZni04oSb2sWgRXbxUWKF9ij68XoD0rYbXMB 1qbbUb014B6BT7fotCguoeqx/uH9VqyN8c3/W/0Am/Mh4zAWeUyI8IcgnB33LwW7zrYA aYKJD8toja2BTGJQpvEqbobHuHg53cBvpG+hD66aoqPhf19/RIOsOarBlLECxAirsRXv vEP+ATG0f+8JOw1MVdFaLm+q0fXmRLFDwL8Kmd2nSN6RD0/HUq166FgN/R2ZRmwPL3q0 ztKg== X-Gm-Message-State: AOAM530iLtQEy0DFHe2Q6wTx7xk8cC2IXMFxd9Oyp82uTWLAgLwOXRhe OsJLK6apbpnGEFXJ78ZwtdD7+k90iNuMxQfs/e0= X-Google-Smtp-Source: ABdhPJwclDnjooXxW+2JiwsqWX8ZQ6WRjSqtRpFsfEtc2+ujHL2mzhDvDBhodN1v9fm+8W5GNhfI0n4AgUSRs30RlSA= X-Received: by 2002:a02:e4a:: with SMTP id 71mr8723575jae.133.1598810513366; Sun, 30 Aug 2020 11:01:53 -0700 (PDT) MIME-Version: 1.0 References: <7d91bd8f-9ca0-4e62-886b-f89bc8edd3e9@www.fastmail.com> In-Reply-To: Date: Sun, 30 Aug 2020 21:01:42 +0300 Message-ID: To: tyson andre Cc: Larry Garfield , PHP internals Content-Type: multipart/alternative; boundary="000000000000b6616705ae1c145d" 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) --000000000000b6616705ae1c145d 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 > } > Of course it should have been `$element = first($collection, fn($elt) =>..., $none);` -- Best regards, Bruce Weirdan mailto: weirdan@gmail.com --000000000000b6616705ae1c145d--