Your version includes 4 variables. Pipes don't create those intermediate variables, so they are more memory efficient.
Readability is mostly matter of habit. One reads easily what he/she is used to read.
Readability is mostly matter of habit. One reads easily what he/she is used to read.
That's like saying someone would use this:
$result = $arr |> fn($x) => array_column($x, 'tags') |> fn($x) => array_merge(...$x) |> array_unique(...) |> array_values(...)
which is harder to reason about than the nested functions. array_values( array_unique( array_merge( ...array_column($arr, 'tags') ) ) );
or array_values(
array_unique(
array_merge(
...array_column($arr, 'tags')
)
)
); $result = $arr
|> fn($x) => array_column($x, 'tags')
|> fn($x) => array_merge(...$x)
|> array_unique(...)
|> array_values(...)
vs array_values(
array_unique(
array_merge(
...array_column($arr, 'tags')
)
)
);
With pipes you have linear sequence of data transformations. With nested function calls you have to start with innermost function and proceed all the way top the outermost layer.They can be. It depends on the language, interpreter, compiler, and whether you do anything with those intermediate variables and the optimiser can get rid of them.