PHP code example of md / lambda-preprocessor

1. Go to this page and download the library: Download md/lambda-preprocessor 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/ */

    

md / lambda-preprocessor example snippets


$id = function($x) { return $x };

$id = $x ==> { $x };

$addNumbers = ($x, $y) ==> { $x + $y };

$addNumbers = function ($x, $y) { return $x + $y };

$addNumbers = (int $x, int $y): int ==> { $x + $y };

$addNumbers = function (int $x, int $y): int { return $x + $y };

$increment = $x ==> {
    $y = $x + 1;
    return $y;
};

$increment = function($x) {
    $y = $x + 1;
    return $y;
};

function addLastname(array $names, string $lastname): array
{
    return array_map($name ==> { $name . " " . $lastname }, $names);
}

function addLastname(array $names, string $lastname): array
{
    return array_map(function($name) use ($lastname) { return $name . " " . $lastname }, $names);
}

$lambda = $x ==> { $y ==> { $x + $y }; };

$lambda = function($x) { return function($y) { return $x + $y; }; };