On Tue, May 3, 2016 at 12:53 PM, Terry Cullen <te...@terah.com.au> wrote:
> Doesn't Nikic's scalar objects (https://github.com/nikic/scalar_objects) > more or less achieve the same thing while also cleaning up the std lib? > > $ret = scandir($arg) > ->filter(function(){}) > ->map(function(){}) > ->merge($someOtherArray); > This type of solution is only applicable if the operations to be chained can be bundled with the definition of the type itself, and are generic enough that they should be. Consider the pipe between scandir() and array_filter(...). Suppose I already have a function or method removeDots(array $paths):array which I would like to use: $ret = scandir($arg) |> $this->removeDots($$) |> ... If the solution is method chaining, then either removeDots() has to be added to PHP's built-in array type, or scandir() must return a specific class (eg FileList) which has such a method, instead of a simple array. Either way, the author of either scandir() or of the "array" type must predict what operations the user is going to want to chain. That isn't knowledge they necessarily have, especially since the operations could be entirely specific to their use case. With the pipe operator, all three of the left hand side, right hand side and the type flowing between them can belong to different codebases.