PHPackages                             chh/funk - 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. chh/funk

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

chh/funk
========

A minimal functional programming library for PHP

210PHP

Since Oct 13Pushed 13y ago3 watchersCompare

[ Source](https://github.com/CHH/funk)[ Packagist](https://packagist.org/packages/chh/funk)[ RSS](/packages/chh-funk/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Funk
====

[](#funk)

[Funk](http://github.com/CHH/Funk) is a minimal functional library for PHP.

It's a collection of some things, I've felt the need for in many projects:

- Dealing with Currying, memoizing and limiting calls to functions (`Funk\Func`).
- Common collection operators which deal in a uniform way with both arrays **and** Iterators (`Funk\Collection`).
- A tight wrapper around casting operations, which also deals with casting objects to scalars (`Funk\Type`).

Install
-------

[](#install)

Install with [Composer](http://getcomposer.org):

```
php composer.phar require chh/funk:*@dev

```

Then require `vendor/autoload.php` in your application.

Collection
----------

[](#collection)

The `Funk\Collection` class wraps a PHP iterable value and provides methods to manipulate it. The collection provides nearly all operations using Iterators and exposes this iterator via `getIterator` (also implements `IteratorAggregate`). That means that nearly all operations are lazy evaluated.

You can see this in action, if you wrap a PDO statement in a collection and then call `map`. This wraps the PDO Statement in a special "MappingIterator", which applies the callback function on each element and yields the callback's return value. But this happens only when the "MappingIterator" is iterated, until then nothing happens.

Example:

```
