Re: [RFC] Global functions any() and all() on iterables

From: Date: Tue, 01 Sep 2020 23:35:46 +0000
Subject: Re: [RFC] Global functions any() and all() on iterables
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-111769@lists.php.net to get a copy of this message
> Perhaps we could do the same thing by introducing an items() function > that takes an iterable and yields one array for each item in the > iterable. The arrays contain the key/value pairs. Quoting the example > Tyson gave: > >   any($itemMap, fn($enabled, $itemId) => $enabled && >   meetsAdditionalCondition($itemId), ARRAY_FILTER_USE_BOTH) > > Using items(), the above can also be written as: > >   any(items($itemMap), fn($item) => $item[0] && >   meetsAdditionalCondition($item[1])) This could be called various things (items(), entries(), iterable_items(): Traversable) and there'd be the question of whether array_items(array $entries): array<array{0:int|string,1:mixed}> should also be added (return a list of key+value entries). I'd expect items(): iterable to definitely have more performance overhead than $flag=0 due to the extra method calls to next() and key() on the result but potentially be better for readability or working with generators. There's many proposed ways to solve that problem (adding int $flag=0, any_item(iterable, callable($value, $key)), etc.), so I'm leaving it out of the RFC Thanks, - Tyson

« previous php.internals (#111769) next »