Re: Straw poll: Naming for `*any()` and `*all()` on iterables

From: Date: Mon, 21 Dec 2020 17:39:39 +0000
Subject: Re: Straw poll: Naming for `*any()` and `*all()` on iterables
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-112575@lists.php.net to get a copy of this message
On Sat, Dec 19, 2020 at 2:24 PM tyson andre <tysonandre775@hotmail.com> wrote: > I've created a straw poll for the naming pattern to use for > *any() and > *all() on iterables. > https://wiki.php.net/rfc/any_all_on_iterable_straw_poll > > This is probably going to be a terrible idea because it involves a little magic but... "iterable" is already a forbidden userspace class name since it's reserved for the psuedo-type which is a union of Traversable | array. What if we went ahead and defined an actual (abstract-final) iterable class. The parser rules which treat iterable as a special type still apply, so we never try to match instances of class iterable, but what we can do is define methods on it. class Iterable { static public function any(iterable $iter, Callable $predicate): bool { ... } static public function all(iterable $iter, Callable $predicate): bool { ... } } Then the API is both 100% searchable (the man page for iterable can explain that it's a pseudo-type AND that it has helper methods), and intuitive to read/write. if (iterable::any($iter, fn($elem) => $elem === 'foo')) { }

« previous php.internals (#112575) next »