Skip to content

Instantly share code, notes, and snippets.

@sgolemon
Created January 10, 2015 01:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgolemon/50425dffc0ed09cf2cc5 to your computer and use it in GitHub Desktop.
Save sgolemon/50425dffc0ed09cf2cc5 to your computer and use it in GitHub Desktop.
Short Lambda Syntax
<?php
$names = ['Alice', 'Bob'];
// PHP Closures
$greetings = array_map(
function($x) {
return "Hello $x";
}, $names);
// HHVM's short-lambda version
$greetings = array_map($x ==> "Hello $x", $names);
@TomHAnderson
Copy link

Perhaps the parameter into ==> can be aliased as ~ ?
And with PSR7 can we reduce the request to $__ ?

<?php

$result = false;

$procedure = [
    'minifiy();',
    'reduce();',
    'squish()',
];

foreach ($procedure as $call) {
    $result .==> eval($call);
}

return $result;

@anubisthejackle
Copy link

Or you can do the same thing, without having to expose your codebase to eval:

<?php

$result = false;

$procedure = [
    'minifiy',
    'reduce',
    'squish',
];

foreach ($procedure as $call) {
    $result .==> $call();
}

return $result;

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