PHP code example of reasno / compose-mixins

1. Go to this page and download the library: Download reasno/compose-mixins library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reasno / compose-mixins example snippets


use function Reasno\Helpers\composeMixins;
use Reasno\Helpers\Recipe;

$c = composeMixins(new Recipe('pipe'), /* callable */ $a, /* callable */ $b);
$result = $c($input); //Use the composed function


$result1 = $c($input);
$result2 = $a($b($input));

var_dump($result1 === $result2); //true

function composeMixins(Recipe $recipe, callable ...$mixins) 

new Recipe('map');

/* use a different handler each time the composed function is called */
$r = Recipe::fromCallable(function(...$fns){
	static $i = 0;
	return function($input) use (&$i, $fns){
		try{
			return $fns[$i++]($input);
		} catch( Error $e ){
			return null;
		}

	};
});

Class MyRecipeHandler{
	//...
}
$CustomRecipe = new Recipe('fancy', ['handler' => 'MyRecipeHandler']);
 tests/composeMixinsTest.php