Re: [RFC] Pipe Operator (again)
| From: | Côme Chilliet | Date: | Tue, 11 Mar 2025 09:00:52 +0000 |
| Subject: | Re: [RFC] Pipe Operator (again) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126711@lists.php.net to get a copy of this message | ||
Hello,
I’m also wondering when I see code examples in the RFC like:
$profit = [1, 4, 5]
|> loadMany(...)
|> fn(array $records) => array_map(makeWidget(...), $records)
|> fn(array $ws) => array_filter(isOnSale(...), $ws)
|> fn(array $ws) => array_map(sellWidget(...), $ws)
|> array_sum(...);
This would be way better on performances as a single foreach, no?
I feel like this pipe operator encourages coders to use array_* functions with closures, which is
often terrible performances compared to a loop.
How would the performance of the above compare with:
$profit = 0;
foreach (loadMany($input) as $item) {
$widget = makeWidget($item);
if (!isOnSale($widget)) {
continue;
}
$profit += sellWidget($widget);
}
Côme
Attachment: [application/pgp-signature] This is a digitally signed message part. signature.asc
Attachment: [application/pgp-signature] This is a digitally signed message part. signature.asc