Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111735 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25177 invoked from network); 31 Aug 2020 03:04:02 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 31 Aug 2020 03:04:02 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5C60D1804AA for ; Sun, 30 Aug 2020 19:08:20 -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,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-f180.google.com (mail-il1-f180.google.com [209.85.166.180]) (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 19:08:19 -0700 (PDT) Received: by mail-il1-f180.google.com with SMTP id t13so5175452ile.9 for ; Sun, 30 Aug 2020 19:08:19 -0700 (PDT) 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=TuDc9eTjKu8NpN3Ed+cqcCCtGdOp2qCye9QfhaVMTKo=; b=HI2wyzBbtLOFzd6+mO7h2rB0lCQZLWwFT9ZyjAeIhjSPklJVLb+/CaNGC18LS/CLMe I7R2/Jpdsz0P/5AwKHtQ/Zbj1qR96mc+hUj+iVTZjn3hn1xJTjPOS79P+G3MSD0h3ET8 o+gH9T0eHm1kJS9j9tdm+yUAbsDF7b0JnffpY= 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=TuDc9eTjKu8NpN3Ed+cqcCCtGdOp2qCye9QfhaVMTKo=; b=W84qw64WAokbRKw87Ic2QSaMfv0rRSKtcRayPB6Hxs1794+Y/ESBsO4oGRNCWk/F/K rgZPdAvKgQ2yfFNO5dZE85asKVaKi+rzovrx531wf7f5d/j5l0rdlLjliv7uhwofzr81 6u9mrzVtte4fPEmDpAnTcx07DlbSgSXvxwJPJyQSQXaB5xmP+HRe1FSuHWpioTziJWrz 7Xo0XOF8FQvSJ9UGwj5M+RzIKDbhqo7tuJ3f1l6+uwNJGeI8jc0E2WE1XcRWBeyD9wha diMCtMfEW6+AtiJ2k3M2gou3ySBNuJ/a8PwES7omkEvlaAbKWuP+R/+HTGO4JJLA4FEe GtCA== X-Gm-Message-State: AOAM532OOZoTKMXmCnIP8MiO1NoTpt4/uHA814HpoADbjvcj10ki0UQ7 VX8G7ERLOA4nvOp5Nx4O6XIQF8c2dltltOMDfpse8Q== X-Google-Smtp-Source: ABdhPJx2uPx2w3/XvIuHXc4IioF6Jqez92oF+eMy7t/8l7qmXRtARtuo6caIMBDCVrc6m5CNM9UtNNzPtDJd4XSoce8= X-Received: by 2002:a92:c50e:: with SMTP id r14mr7609771ilg.161.1598839696563; Sun, 30 Aug 2020 19:08:16 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: Levi Morrison Date: Sun, 30 Aug 2020 20:08:05 -0600 Message-ID: To: tyson andre Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) From: internals@lists.php.net ("Levi Morrison via internals") I was actually working on this sort of thing recently. _Technically_, you can support `all`, `any`, and `first` by using a single function: function find_first(iterable $of, callable($value, $key): bool $thatSatistifes): Iterator It converts the $iterable into an Iterator, then calls the callback for each key/value pair until one returns true, and then always returns the iterator at the current position. 1. This allows you to know both key and value when making a decision. 2. By returning an iterator the caller can get both key and value. 3. By returning an iterator it can handle both the empty case and not found cases with $result->valid() === false. 4. By returning an iterator it might be useful for processing the remainder of the list somehow. I'm not sure that in practice it would be that friendly, but it's worth pointing out for discussion at least.