PHPackages                             perryflynn/perrys-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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. perryflynn/perrys-lambda

AbandonedArchivedLibrary[Parsing &amp; Serialization](/categories/parsing)

perryflynn/perrys-lambda
========================

Implementation of lambda expressions for PHP.

0.2.1(8y ago)2385[3 issues](https://github.com/perryflynn/PerrysLambda/issues)1MITPHPPHP &gt;=5.5.0

Since Apr 15Pushed 8y ago1 watchersCompare

[ Source](https://github.com/perryflynn/PerrysLambda)[ Packagist](https://packagist.org/packages/perryflynn/perrys-lambda)[ Docs](https://github.com/perryflynn/PerrysLambda)[ RSS](/packages/perryflynn-perrys-lambda/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (6)Used By (1)

This project tries to implement C# .NET lambda expressions in PHP.

[![Build Status](https://camo.githubusercontent.com/6a7c1e75c91d8bf8bf96c4f1134359ecb8a5ccb676aef0be34bb3d949eca10ab/68747470733a2f2f7472617669732d63692e6f72672f7065727279666c796e6e2f5065727279734c616d6264612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/perryflynn/PerrysLambda) [![Coverage Status](https://camo.githubusercontent.com/acf814a39e1731f25f10d20242b2df04dde9ffc267c7c7a8797f487cec552c49/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7065727279666c796e6e2f5065727279734c616d6264612f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/perryflynn/PerrysLambda?branch=master)

Status
------

[](#status)

In development, semi-stable API.

Composer
--------

[](#composer)

[Packagegist](https://packagist.org/packages/perryflynn/perrys-lambda)

```
composer require perryflynn/perrys-lambda

```

Features
--------

[](#features)

- Implements many C# .NET like lambda expressions
- Support for auto conversion of records in custom objects
- Support for iteation and foreach
- Support for [generator](http://php.net/manual/en/language.generators.syntax.php) (helps with call-by-reference in loops)
- Helper classes for filesystem access
- Helper classes for CSV file parsing

Lambda methods
--------------

[](#lambda-methods)

MethodDescription\*OrDefaultDefine return value if expression has no hit, available for many methods`first`Get the first record`last`Get the last record`single`Get the single record, if `count!=0`, throw exception`take`Get the first `X` records`skip`Skip the first `X` records`where`Filter records by `callable` expression`whereFirst`Get first record matching the `callable` expression`groupby`Group records by `callable` expression`distrinct`Eliminate duplicate records bei `callable` expression`intersect`Returns the intersection of two ArrayList's`except`Returns the bidirectional diffrence of two ArrayList's`any`Returns true if `callable` expression returns at least one record `true``all`Returns true if `callable` expression returns for all records `true``select`Get an `array` of the values returned by `callable` expression`selectMany`Get an `array` of all values, arrays will be merged`joinString`Join a string from values returned by `callable` expression`each`Execute `callable` expression on each record`sum`Get the sum of numberic return values from `callable` expression`min`Get the smallest of numberic return values from `callable` expression`max`Get the biggest of numberic return values from `callable` expression`avg`Get the average of numberic return values from `callable` expression`order`Start sorting, begin ascending, more possible by `thenBy` / `thenByDesc``orderDesc`Start sorting, begin descending, more possible by `thenBy` / `thenByDesc`Basic usage
-----------

[](#basic-usage)

```
$basic = new \PerrysLambda\ArrayList(array(1,2,3,4,5,6,7,8,9));

$basic->where(function($n) { return $nwhere(function($n) { return $nsum(); // Returns 6
```

Basic usage with ObjectArray and Strings instead of callables
-------------------------------------------------------------

[](#basic-usage-with-objectarray-and-strings-instead-of-callables)

```
$data = array(
    array('name'=>'Frank', age=>12),
    array('name'=>'Gene', age=>42),
    array('name'=>'Jessie', age=>31),
    array('name'=>'Carl', age=>55),
);

$list = \PerrysLambda\ArrayList::asObjectArray($data);
$list->select('age')->sum(); // Returns 140
$list->where(function($v) { return $v->age > 40; })->select('age')->sum(); // Returns 97
```

Deserialize / Serialize
-----------------------

[](#deserialize--serialize)

- Deserialize json data
- Modify data
- Serialize again into json data
- Display modified json data

```
// examples/serialize.php

use PerrysLambda\ArrayList;
use PerrysLambda\ObjectArray;
use PerrysLambda\IArrayable;
use PerrysLambda\Converter\ItemConverter;
use PerrysLambda\Serializer\Serializer;
use PerrysLambda\Serializer\DateTimeSerializer;
use PerrysLambda\Serializer\BooleanSerializer;
use PerrysLambda\Converter\ListConverter;

// Testdata
$rawstring = setFieldSerializers(array(
    "barfoo" => DateTimeSerializer::fromIsoFormat(),
    "foobar" => new BooleanSerializer(),
));

// Create converter
$conv = new ListConverter();
$conv->setItemConverter($fieldconverter);
$conv->setArraySource($rawlines);

// Load raw data into ArrayList
$list = new ArrayList($conv);

// Modify data
$list
    ->where(function($v) { return $v->foobar===true; })
    ->each(function($v) { $v->foo = $v->foo+1; });

// Serialize modified data
$serlines = $list->serialize();
var_dump($serlines);
```

More examples
-------------

[](#more-examples)

[See the unit tests](test/)

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Every ~73 days

Total

5

Last Release

3063d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d6b2d4181af2266ff9fd59836fd742c457dad8e0234826f3238a9553c023e30f?d=identicon)[perryflynn](/maintainers/perryflynn)

---

Top Contributors

[![perryflynn](https://avatars.githubusercontent.com/u/1693988?v=4)](https://github.com/perryflynn "perryflynn (108 commits)")

---

Tags

deserializationlambdalambda-expressionsphpserializationphpdataexpressionslambda

### Embed Badge

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

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

###  Alternatives

[apache/avro

Apache Avro™ is a data serialization system.

3.3k50.6k3](/packages/apache-avro)[nikic/phlexy

Lexing experiments in PHP

162589.7k14](/packages/nikic-phlexy)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

23790.9k2](/packages/corveda-php-sandbox)[friendsofcxml/cxml-php

PHP Implementation of cXML Standard

16131.4k7](/packages/friendsofcxml-cxml-php)[bupy7/xml-constructor

The array-like constructor of XML document structure.

1338.9k](/packages/bupy7-xml-constructor)

PHPackages © 2026

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