> 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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to