Skip to content

Instantly share code, notes, and snippets.

@vielhuber
Last active July 20, 2025 11:38
Show Gist options
  • Save vielhuber/fb641d173981773b8f6b2bc0d18773bd to your computer and use it in GitHub Desktop.
Save vielhuber/fb641d173981773b8f6b2bc0d18773bd to your computer and use it in GitHub Desktop.
pipe operator |> #php

old syntax

$value = "hello world";

// short version
$result = function1(function2(function3($value)));

// long version
$result1 = function3($value);
$result2 = function2($result1);
$result = function1($result2);

new syntax

$value = "hello world";
$result = $value
    |> function3(...)
    |> function2(...)
    |> function1(...);

example with values

$value = 'Lorem Ipsum';
$result = $value
    |> fn($x) => explode(' ', $x)
    |> fn($x) => implode('_', $x)
    |> strtolower(...)
; // lorem_ipsum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment