PHPackages                             md/lambda-preprocessor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. md/lambda-preprocessor

ActivePre-macro[Utility &amp; Helpers](/categories/utility)

md/lambda-preprocessor
======================

0.1.0(8y ago)48MITPython

Since Jul 15Pushed 8y agoCompare

[ Source](https://github.com/MarcelloDuarte/lambda-preprocessor)[ Packagist](https://packagist.org/packages/md/lambda-preprocessor)[ RSS](/packages/md-lambda-preprocessor/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

A hack-like lambda syntax for PHP
=================================

[](#a-hack-like-lambda-syntax-for-php)

In [Hacklang](https://docs.hhvm.com/hack/lambdas/introduction), a lambda expression is denoted by using the lambda arrow `==>`. Left of the arrow are arguments to the anonymous function and on the right hand side is either an expression or a list of statements.

This pre-processor is meant to make that syntax available in native PHP applications. This does not happen at runtime, so there is no hit on perfomance. The pre-processor works on top of the [pre](https://github.com/preprocess/pre-plugin) plugin and the [yay macro library](https://github.com/marcioAlmada/yay).

Syntax wise, and due to the fact that Yay does not have an expresison parser yet, even though Hack supports a single expression to be written without the need of curly brakets, this pre-processor will always require the curly brakets to be written. Hopefully this will change once Yay develops further.

Oneliner anonymous function
---------------------------

[](#oneliner-anonymous-function)

The simplest example is an anonymous function that returns the argument it was given in the first place. In PHP it could be written as:

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

Which can be written, using this pre-processor, much simpler:

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

Should we need to declare typehints or pass more than one argument, we will need to use parenthesis. We could also use parenthesis in the example above, but it is optional for single arguments with no type hinting.

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

Which is translated to:

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

Or with type hints:

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

Which is translated to:

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

Multiple lines anonymous functions
----------------------------------

[](#multiple-lines-anonymous-functions)

The same rules for arguments, typehints and return types still apply for anonymous functions with multiple lines. The only difference is that you will need to write the `return` keyword in the last statement of the block, and you must now end every statement with a semicolon.

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

This is translated into:

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

Closures
--------

[](#closures)

PHP provides the keyword `use` to capture variables from the enclosing scope. Hack's lambdas make this even easier. You can use variables implicitly inside of a lambda. This is available when you use this pre-processor.

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

Note that to use `$lastname` with the official syntax you would have to use the `use` keyword, as shown below:

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

Recursive calls and precedence
------------------------------

[](#recursive-calls-and-precedence)

The pre-processor will translate the inner block and then the outer. The precedence with this syntax is a bit more obvious than the hack one. In hack you can ommit the brakets `{`, `}`. Here, it should be straightforward that the expression:

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

will be translated into:

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

Final Notes
-----------

[](#final-notes)

- This pre-processor is alpha software. Do not use it in production.

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3225d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/126c34b4dff8d42336ea07ac5297bcc3ec0a0e306fd964a7497f02240da4b142?d=identicon)[md](/maintainers/md)

---

Top Contributors

[![MarcelloDuarte](https://avatars.githubusercontent.com/u/144535?v=4)](https://github.com/MarcelloDuarte "MarcelloDuarte (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/md-lambda-preprocessor/health.svg)

```
[![Health](https://phpackages.com/badges/md-lambda-preprocessor/health.svg)](https://phpackages.com/packages/md-lambda-preprocessor)
```

###  Alternatives

[pre/plugin

941.4k3](/packages/pre-plugin)[trafiklab/gtfs-php-sdk

Use GTFS and GTFS-realtime data in your PHP projects

175.3k](/packages/trafiklab-gtfs-php-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
