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 call
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:
> >
> > https
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, $a
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, fn($e
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()
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 i
> 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
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
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 be
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 make
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
array_as_stri
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
> 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. first(
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 t
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.
>
> -
> https://hackage.haskell.org/package/base-4.14.0.0/docs/Prelude.html#v:any
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
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 or(
>>
>> - 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
18 matches
Mail list logo