Skip to content

Instantly share code, notes, and snippets.

@iiidefix
Created March 7, 2022 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iiidefix/4b53d835a46fa2fd7431f53bc5d333ef to your computer and use it in GitHub Desktop.
Save iiidefix/4b53d835a46fa2fd7431f53bc5d333ef to your computer and use it in GitHub Desktop.
simple php pipe function
<?php
function pipe($value, ...$funcs) {
return array_reduce($funcs, fn($v, $f) => $f($v), $value);
}
?>
@iiidefix
Copy link
Author

iiidefix commented Mar 7, 2022

Usage

// Equivalent to: function3(function2(function1($v)))

pipe($v, 
	fn($v) => function1($v), 
	fn($v) => function2($v), 
	fn($v) => function3($v),
	...
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment