Re: Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...)

From: Date: Tue, 01 Sep 2020 00:03:04 +0000
Subject: Re: Proposal: Adding functions any(iterable $input, ?callable $cb = null, int $use_flags=0) and all(...)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-111757@lists.php.net to get a copy of this message
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

« previous php.internals (#111757) next »