Re: [RFC] Pipe Operator (again)

From: Date: Sat, 29 Mar 2025 14:46:16 +0000
Subject: Re: [RFC] Pipe Operator (again)
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-126973@lists.php.net to get a copy of this message
Hi Ilija and Larry, thank you so much for your great work bringing PHP forward. I have been passively reading this list for a while and would like to chime in with two thoughts. > Pipes would no longer have the form of expr |> expr, where the right-hand-side is expected > to return a callable. Instead, it would have the form of expr |> function_call, where the > left-hand-side is implicitly inserted as the first parameter of the call. > >namespace Iter { > function map(iterable $iterable, \Closure $callback): \Iterator; > function filter(iterable $iterable, \Closure $callback): \Iterator; >} > >namespace { > use function Iter\{map, filter}; > > $result = "Hello World" > |> str_split() > |> map(strtoupper(...)) > |> filter(fn($v) => $v != 'O'); >} With named parameters, you could even make this approach work without the suggested (but still useful) new Iterator API: $result = "Hello World" |> str_split() |> array_map(callback: strtoupper(...)) |> array_filter(callback: fn($v) => $v != 'O'); or $result = "Hello World" |> str_split() |> array_map(callback: strtoupper(...)) |> array_filter(fn($v) => $v != 'O'); I am also wondering whether |> and -> should have the same operator precedence. Best regards, Olaf Schmidt-Wischhöfer

« previous php.internals (#126973) next »