Re: A little syntactic sugar on array_* function calls?
| From: | someniatko | Date: | Tue, 25 May 2021 10:51:16 +0000 |
| Subject: | Re: A little syntactic sugar on array_* function calls? | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-114581@lists.php.net to get a copy of this message | ||
> The proposed syntax
>
> $array |> array_map($fn1, ?) |> array_filter(?, $fn2)
>
> When I compare to:
>
> $array->map($fn1)->filter($fn2)
>
> 1. It's longer. Much longer.
> 2. It still requires knowing where the array goes. That's legacy which we could sidestep
> with the arrow notation.
> 3. Admittedly, the pipe is much more powerful.
While the argument No. 2. is completely valid, the 1st one is not so.
If you remove whitespaces around the
|> and also if you alias these
functions to map and filter respectively (or if, for instance,
some future RFC moves them into a special PHP\Array namespace, which
would probably never happen, but it's allowed to dream), it could look
like this:
```php
$array|>map($fn1, ?)|>filter(?, $fn2);
$array->map($fn1)->filter($fn2);
```
A bit longer (due to 2.), but not that much, actually.
Best wishes,
someniatko