PHPackages                             simones/lambda - 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. simones/lambda

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

simones/lambda
==============

Create closures from definition strings.

011PHP

Since Aug 28Pushed 9y ago1 watchersCompare

[ Source](https://github.com/SimoneS93/Lambda)[ Packagist](https://packagist.org/packages/simones/lambda)[ RSS](/packages/simones-lambda/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Lambda
======

[](#lambda)

Create closures from definition strings.

Install
-------

[](#install)

```
composer require simones/lambda
```

How to use
----------

[](#how-to-use)

You generate closures passing a definition string to the `Lambda` constructor or to `Lambda::make`: they will return a `Lambda` instance, that you can call directly (it implements the `__invoke` magic method) or via the `call` method, passing an optional array of arguments.

Defition strings format
-----------------------

[](#defition-strings-format)

Definitions are in the format `arguments => body`, borrowed from languages like Coffescript. So, for example, the following

```
$increment = new Lambda('$x => $x + 1');
```

will translate in something like:

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

Multiple arguments are allowed and complex expressions can be used as the body. If the arguments part is not present, the variables `x, y, z` will be automatically injected and defaulted to `NULL`; so the above code could be written as:

```
$increment = new Lmabda('$x + 1');

// or with the lambda helper

$increment = lambda('$x + 1');

// and translates to

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

You're allowed to use as many parameters as wanted and arbitrary complex body definitions, though I recommend you to use mainly for short anonymous functions (I wrote this to be used with Laravel Collection's `map` and `filter` methods).

Here's a spec case that tests the use with complex code:

```
function it_allows_complex_code()
    {
        $this
            ->make('$int, $string, $array => strval($int) . strtoupper($string) . $array[0]')
            ->call([100, ' times ', ['Lambda!']])
            ->shouldBe('100 TIMES Lambda!');
    }
```

Limits
------

[](#limits)

At this stage, no syntax check is done on the code, so you should input only trusted and well-formed definitions. It just wraps your code in a function definition, adds minor structure controls and throws exceptions when it can't do its job. I added a spec suite to test the intended behaviour, but it's my first package and I don't really feel it should be used in production as is.

Bugs and improvements
---------------------

[](#bugs-and-improvements)

Every help is welcome to improve the package: just create a pull request.

###  Health Score

20

—

LowBetter than 13% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/534436?v=4)[SimoneS](/maintainers/SimoneS)[@simones](https://github.com/simones)

---

Top Contributors

[![SimoneS93](https://avatars.githubusercontent.com/u/6176258?v=4)](https://github.com/SimoneS93 "SimoneS93 (7 commits)")

### Embed Badge

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

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

###  Alternatives

[ite/form-bundle

Improve Symfony 2 forms by adding new features and integration with popular JavaScript libraries and jQuery plugins.

1420.1k](/packages/ite-form-bundle)

PHPackages © 2026

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