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

2020-08-30 Thread Levi Morrison via internals
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

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

2020-08-30 Thread Larry Garfield
On Sun, Aug 30, 2020, at 3:43 PM, tyson andre wrote: > Hi Dik Takken, > > > I would love to see this come to PHP. I also do a lot of Python > > development and I really like its operators module, which provides > > function equivalents to the intrinsic Python operators. Have a look: > > > >

Re: [PHP-DEV] array_reject() as counterpart of array_filter()

2020-08-30 Thread Larry Garfield
On Sun, Aug 30, 2020, at 9:38 AM, David Rodrigues wrote: > Currently we have array_filter(), but sometimes we need an inverse function > like array_reject(). > > array_reject('is_null', [ 1, 2, null, 3 ]); // [ 1, 2, 3 ] > > It could be easily implemented with: > > function array_reverse($fn,

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

2020-08-30 Thread tyson andre
Hi Bruce Weirdan, > If it took the default value as well it could return that. While it's useful > in itself it also would enable you to pass > a marker object and check the > identity of that to know if no matches have been found: > > $none = new stdClass; > $element = first($collection,

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

2020-08-30 Thread tyson andre
Hi Dik Takken, > I would love to see this come to PHP. I also do a lot of Python > development and I really like its operators module, which provides > function equivalents to the intrinsic Python operators. Have a look: > > https://docs.python.org/3/library/operator.html > > Although the any()

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

2020-08-30 Thread Dik Takken
On 29-08-2020 22:24, tyson andre wrote: > Hi internals, > > The primitives any() and all() are a common part of many programming > languages and help in avoiding verbosity or unnecessary abstractions. I would love to see this come to PHP. I also do a lot of Python development and I really like

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

2020-08-30 Thread Bruce Weirdan
> On Sun, Aug 30, 2020 at 6:13 PM tyson andre > wrote: > >> > I like this, but I do not like the flags. I don't think they're at all >> useful. A lot of the other discussion in the thread seems to be needlessly >> complicating it, too. >> > >> > all() and any() only need return booleans. Their

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

2020-08-30 Thread Bruce Weirdan
On Sun, Aug 30, 2020 at 6:13 PM tyson andre wrote: > > I like this, but I do not like the flags. I don't think they're at all > useful. A lot of the other discussion in the thread seems to be needlessly > complicating it, too. > > > > all() and any() only need return booleans. Their callbacks

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

2020-08-30 Thread tyson andre
Hi Mike Schinkel, > Doesn't the occasional required use of long constant names like > ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_BOTH somewhat negative the benefit > of a more concise syntax? > > I know that many existing functions in PHP have a collection of long constant > names that can

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

2020-08-30 Thread tyson andre
Hi Marco Pivetta, > Would it make sense, instead of having a third boolean parameter (causing two > parameters to be coupled together - already quite messy with existing array > functions) for `any()` and `all()` to just detect if the given callback > requires >1 parameter? > > That would

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

2020-08-30 Thread Josh Bruce
Thanks. Re the name, I see that. I think part of the approachability of PHP is in the language being more common - though not being consistent in use of math, computer science, or common can be frustrating as all. join() (math) -> alias of implode() (cheeky common??) -> could be

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

2020-08-30 Thread tyson andre
Hi Josh Bruce, > The compelling feature here for me is the idea of an “array walker” that can > be broken out of. > > all() could be and() at which point this should be equivalent. Yes, you can write `all($set, $predicate_fn)` as `!any($set, fn($x) => !$predicate_fn($x))` or some other common

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

2020-08-30 Thread tyson andre
> I like this, but I do not like the flags.  I don't think they're at all > useful.  A lot of the other discussion in the thread seems to be needlessly > complicating it, too. >  > all() and any() only need return booleans.  Their callbacks only need return > booleans.  That's the point. 

[PHP-DEV] array_reject() as counterpart of array_filter()

2020-08-30 Thread David Rodrigues
Currently we have array_filter(), but sometimes we need an inverse function like array_reject(). array_reject('is_null', [ 1, 2, null, 3 ]); // [ 1, 2, 3 ] It could be easily implemented with: function array_reverse($fn, $arr) { return array_filter(fn($item) => !$fn($item), $arr); } Anyway, I

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

2020-08-30 Thread Larry Garfield
On Sat, Aug 29, 2020, at 3:24 PM, tyson andre wrote: > Hi internals, > > The primitives any() and all() are a common part of many programming > languages and help in avoiding verbosity or unnecessary abstractions. > > - >

Re: [PHP-DEV] [RFC][Discussion] Objects can be declared falsifiable

2020-08-30 Thread Josh Bruce
Hey Tyson, This is great! Thank you so much, sincerely. Still slow goings, which is fine, we have at least a year. lol Static analyzers seem to be the biggest concern to date. Haven’t been able to get one running locally - though I’ve only spent a few minutes here and there; definitely on the

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

2020-08-30 Thread Josh Bruce
Think I’m following. The compelling feature here for me is the idea of an “array walker” that can be broken out of. all() could be and() at which point this should be equivalent. $collection = [1, 2, 3]; If (count($collection) === count(array_filter($collection, “is_int”)) any() could be

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

2020-08-30 Thread Josh Bruce
>> >> - the default is `any($iterable, fn ($value) => ...)` >> - or `any($iterable, fn ($key) => expr, ARRAY_FILTER_USE_KEY)` >> - or `any($iterable, fn ($value, $key) => expr, ARRAY_FILTER_USE_BOTH)` > > Doesn't the occasional required use of long constant names like > ARRAY_FILTER_USE_KEY and

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

2020-08-30 Thread Mike Schinkel
> On Aug 29, 2020, at 7:18 PM, tyson andre wrote: > > Hi Alex, > >> I like it! >> >> What is the $use_flags parameter for? > > It's for deciding what parameters to pass to callback, like > https://www.php.net/array_filter - the reflection name should probably just > be $flag > >