Pipes and method chains
A table function such as filter(...) returns a closure that takes a table. The PHP 8.5 pipe operator |>, pipe(), and a method chain started with phplyr() apply such closures in order and give the same result. Pipelines shows the three forms.
Pipelines
phplyr()
phplyr(Table|Chain $table): ChainStart a method chain on a table: phplyr($t)->filter(...)->head(5). Each method runs the phplyr function of that name, spelled camelCase, so ->groupBy() runs group_by(). get() returns the table, and functions that return something else, such as pull(), return it plainly.
Returns Chain.
pipe()
pipe(mixed $value, callable ...$steps): mixedApply steps to a value in order: pipe($t, filter(...), head(5)) is $t |> filter(...) |> head(5). A step is any callable.
Returns mixed.
Chain methods
phplyr($table) returns a Phplyr\Chain. Each table function runs as the chain method of the same name in camelCase, such as ->groupBy() for group_by(); Functions and methods lists them. A method whose function returns a table returns a new chain, and any other result is returned as it is. A snake_case method name throws BadMethodCallException naming the camelCase method.
->get()
$chain->get(): TableReturns the chain’s table.
->pipe()
$chain->pipe(callable ...$steps): mixedApplies each step to the table in order. Returns a new chain when the result is a table, and the result itself otherwise.
echo
echo $chain;Prints the table, as echo $table does.