I really believe the thing PHP needs the most is a rework of string / array functions to make them more consistent and chain able. Now they are at least chain able.
I'm not a fan of the ... syntax though, especially when mixed in the same chain with the spread operator
sandreas · 11m ago
While I appreciate the effort and like the approach in general, in this use case I really would prefer extensions / extension functions (like in Kotlin[1]) or an IEnumerable / iterator approach (like in C#).
$arr = [
new Widget(tags: ['a', 'b', 'c']),
new Widget(tags: ['c', 'd', 'e']),
new Widget(tags: ['x', 'y', 'a']),
];
$result = $arr
|> fn($x) => array_column($x, 'tags') // Gets an array of arrays
|> fn($x) => array_merge(...$x) // Flatten into one big array
|> array_unique(...) // Remove duplicates
|> array_values(...) // Reindex the array.
;
It’s really not needed, syntax sugar. With dots you do almost the same. Php doesn’t have chaining. Adding more and more complexity doesn’t make a language better.
bapak · 5m ago
Nothing is really needed, C89 was good enough.
Dots are not the same, nobody wants to use chaining like underscore/lodash allowed because it makes dead code elimination impossible.
EGreg · 7m ago
It’s not really chaining
More like thenables / promises
wouldbecouldbe · 5m ago
It looks like chaining, but with possibility of adding custom functions?
I really believe the thing PHP needs the most is a rework of string / array functions to make them more consistent and chain able. Now they are at least chain able.
I'm not a fan of the ... syntax though, especially when mixed in the same chain with the spread operator
1: https://kotlinlang.org/docs/extensions.html#extension-functi...
Dots are not the same, nobody wants to use chaining like underscore/lodash allowed because it makes dead code elimination impossible.
More like thenables / promises