Hi Levi Morrison,

> I was actually working on this sort of thing recently. _Technically_,
> you can support `all`, `any`, and `first` by using a single function:
> 
>     function find_first(iterable $of, callable($value, $key): bool
$thatSatistifes): Iterator
> 
> It converts the $iterable into an Iterator, then calls the callback
> for each key/value pair until one returns true, and then always
> returns the iterator at the current position.
>
> I'm not sure that in practice it would be that friendly, but it's
> worth pointing out for discussion at least.

I'd find the `find($iterable, $callable, $default = null): mixed` to be more 
user-friendly,
personally, and would worry about accidentally increasing memory usage if I 
left one of those iterables around as a saved value or a long-lived local 
variable.

There's plenty of time until the php 8.1 feature freeze, so I don't feel like 
increasing the scope of this RFC
(https://wiki.php.net/rfc/any_all_on_iterable)
even though I would find some version of `find()` with a callback useful.

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

Reply via email to