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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to