Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111730 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98625 invoked from network); 30 Aug 2020 20:12:49 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Aug 2020 20:12:49 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2B1101804C2 for ; Sun, 30 Aug 2020 12:17:01 -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, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 12:17:00 -0700 (PDT) Received: by mail-ej1-f45.google.com with SMTP id nw23so4301683ejb.4 for ; Sun, 30 Aug 2020 12:17:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=QfROwjFmOGe0m00p+mluve2JFsx+Hsm7J8VcNt6eFfg=; b=fCWTZv57d9LxpLwne/Js7B5SN3meKAjpfoyzwr+ytuFo/9T0eR3KypUN65Ma4qN64R bUoj3siMSQC2wOmPcC94SjHB9ZcxuiskL7VO022mqQeSaeyeM5k6m9ItBM6ZFevGvgA6 O9ImPwS+3UCgYvM1wI2msut25pek9LXlQEFdsQpV5WTpxr7hpY3Ra63bQn7izZGHtH8q zpTconaENbnqvTY1gv1wNcGpuR4otLsK7Oce38htAZdOVyC/+pL5fKLMKM6t/7g18OQS pt/EQ6c2sksnMKjazSHJPHFFzZfXtKb1alcgQ3NnSYT/aHuuLTltkZrnspEa1vRZ2bLh gTBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QfROwjFmOGe0m00p+mluve2JFsx+Hsm7J8VcNt6eFfg=; b=GV9hdCzhxyynK7FphFW+Y1kEAcpC4xEvy1C5U1alO9jWJSsehpL5HS0ZVNZCVfhm5V 2t76J9tG/wwPZwkV57TEqWlTLyBW2N6RG/1qpPt+vaa+s9XYp19yWzVwZDztUMC4qIZ0 +epT780hQAtGE8edF40KT4eXKM+4vOKcgJhBrUylPCJSPnnn/9/z4pTPZrn692agBbFW apCJ3Gd6CEQJs83Ato61kYFzFBii3vekwtrFSwgyJOpvBw408mb9yyAbvDG/dmJ/6V5R u81wwj+xF2EGlmLuS7WUtLN1JhxxVRtYRQ1uv7jgye/j8igXGsakybOiiIfillqp0xuM at9Q== X-Gm-Message-State: AOAM533p4wwl+Xx5UIW7DMnLVGcZlk8Itttf7nNgna1GmX5Y8suVfte5 LAWUunY6tDNzuLsWwcvuX57rqstG8zyaBw== X-Google-Smtp-Source: ABdhPJwoEUkdVixeQA/IcoSh6PCNuLcv+tuX8SWlA6iU9gkE1587M3HemxQeoVxUyBPqt0faTFah3Q== X-Received: by 2002:a17:907:119c:: with SMTP id uz28mr8460238ejb.361.1598815017523; Sun, 30 Aug 2020 12:16:57 -0700 (PDT) Received: from ?IPv6:2001:983:6fc5:1:49c7:735:8c90:b4f5? ([2001:983:6fc5:1:49c7:735:8c90:b4f5]) by smtp.gmail.com with ESMTPSA id c90sm5665957edf.43.2020.08.30.12.16.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 30 Aug 2020 12:16:56 -0700 (PDT) To: tyson andre , PHP internals References: Message-ID: <89d77c3c-593b-b5dd-f39c-009575e295a5@gmail.com> Date: Sun, 30 Aug 2020 21:16:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...) From: dik.takken@gmail.com (Dik Takken) On 29-08-2020 22:24, tyson andre wrote: > Hi internals, > > The primitives any() and all() are a common part of many programming languages and help in avoiding verbosity or unnecessary abstractions. I would love to see this come to PHP. I also do a lot of Python development and I really like its operators module, which provides function equivalents to the intrinsic Python operators. Have a look: https://docs.python.org/3/library/operator.html Although the any() and all() functions are my favorites, having the full range of operator functions would be great. That could ultimately yield a proper counterpart to the range of array_* functions which support any iterable in stead of just arrays. Think of a keys() function that is a generalization of array_keys(). This reminds me of the iter library that Nikita created: https://github.com/nikic/iter So yes, this can also be done in user space. Having it built into the language has advantages though: * High adoption rates, making lots of existing PHP code more concise * Possibly better performance Regarding performance: Since we already have opcodes for handling operators, it may be possible to extend these to consume arbitrary numbers of operands from iterables. Then, an operator function like any() would compile into its equivalent operator opcode. Finally, that opcode can probably be JIT compiled into a tight loop in machine code. So a +1 from me for adding any() and all() but let us also consider the general problem of lacking iterable support in PHP. Perhaps that could be the subject of a followup RFC. Regards, Dik Takken