Hi On 10/28/22 15:45, tyson andre wrote:
- `iterable\count(...)` (alias of iterator_count) - `iterable\to_array(Traversable $iterator, bool $preserve_keys = true): array` (alias of iterator_to_array, so that users can stop using a misleading name)
I wonder if this should be made an alias or if the introduction of the namespace this is a good opportunity to revisit the `$preserve_keys = true` default choice. See also this email in the voting discussion for a previous iter*able*_to_array() RFC: https://externals.io/message/102562#102616
- `iterable\any(iterable $input, ?callable $callback = null): bool` - Determines whether any value of the iterable satisfies the predicate. and all() - Determines whether all values of the iterable satisfies the predicate.
I would not make the callable optional. If one really wants to filter on the falsyness of the items, `any($i, fn ($v) => !!$v)` is easy enough.
I'd likely also swap the order of parameters, having the callable first is more natural with a possible pipe operator or partial application.
It also is arguably more readable when using nested function calls, because the callback appears immediately beside the function name:
(Callback first) iterable\count( iterable\filter( fn ($v) => $v > 5 iterable\map( fn ($v) => strlen($v), $iterable ) ) ) vs (Callable last) iterable\count( iterable\filter( iterable\map( $iterable, fn ($v) => strlen($v) ), fn ($v) => $v > 5 ) )
- `iterable\unique_values(iterable $iterable): array {}` Returns true if this iterable includes a value identical to $value (`===`). - `iterable\includes_value(iterable $iterable, mixed $value): bool {}` Returns a list of unique values of $iterable
It appears you mixed up the descriptions here.
Any comments?
Your proposals look good to me. Especially `any` and `all` are something I'm missing somewhat regularly.
Is there a reason there is no `iterable\map()` and `iterable\filter()` (that I used in my example above)?
Best regards Tim Düsterhus -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php