function pipe( ...$transformers )
{
return function( $value ) use( $transformers )
{
return array_reduce(
$transformers,
fn( $buffer, $transformer ) => $transformer( $buffer ),
$value
);
};
}
$transform = pipe(
fn( $text ) => strrev( $text ) ,
fn( $text ) => strtoupper( $text ),
);
echo $transform( 'This text will be reversed and capitalize' ), "\r\n";
echo $transform( 'This text will be reversed and capitalize also!!' );
Last active
May 3, 2024 06:23
-
-
Save nezarfadle/3093175ee45da2089d1d86fd3ff7ab70 to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment