https://github.com/lstrojny/functional-php
Primitives for functional programming in PHP
https://github.com/lstrojny/functional-php
Last synced: 6 months ago
JSON representation
Primitives for functional programming in PHP
- Host: GitHub
- URL: https://github.com/lstrojny/functional-php
- Owner: lstrojny
- License: mit
- Created: 2011-05-22T22:10:40.000Z (over 14 years ago)
- Default Branch: main
- Last Pushed: 2024-05-12T04:24:40.000Z (over 1 year ago)
- Last Synced: 2025-04-30T10:33:51.566Z (6 months ago)
- Language: PHP
- Homepage:
- Size: 1.05 MB
- Stars: 1,977
- Watchers: 76
- Forks: 209
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- favorite-link - PHP 中函数式编程。
- awesome-php - Functional PHP - A functional programming library. (Table of Contents / Architectural)
- awesome-php-cn - Functional PHP - 函数式编程库. (目录 / 建筑 Architectural)
- awesome-projects - Functional PHP - A functional programming library. (PHP / Architectural)
- awesome-php - Functional PHP - A functional programming library. (Table of Contents / Architectural)
- awesome-php - Functional PHP - A functional programming library. (Table of Contents / Architectural)
- fucking-awesome-php - Functional PHP - A functional programming library. (Table of Contents / Architectural)
README
# Functional PHP: Functional primitives for PHP
[](https://github.com/lstrojny/functional-php/actions/workflows/test.yaml)
*NOTE:* functional-php used to come with a C extension that implemented most of the functions natively. As the
performance differences weren’t that huge compared to the maintenance cost it has been removed.
A set of functional primitives for PHP, heavily inspired by [Scala’s traversable
collection](http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/library/scala/collection/Traversable.html),
[Dojo’s array functions](http://dojotoolkit.org/reference-guide/quickstart/arrays.html) and
[Underscore.js](http://underscorejs.org/)
- Works with arrays and everything implementing interface `Traversable`
- Consistent interface: for functions taking collections and callbacks, first parameter is always the collection, then the callback.
Callbacks are always passed `$value`, `$index`, `$collection`. Strict comparison is the default but can be changed
- Calls 5.3 closures as well as usual callbacks
- All functions reside in namespace `Functional` to not raise conflicts with any other extension or library
[](http://xkcd.com/1270/)
## Installation
Run the following command in your project root:
composer require lstrojny/functional-php
## Docs
[Read the docs](docs/functional-php.md)
## Contributing
1. Fork and `git clone` the project
2. Install dependencies via `composer install`
3. Run the tests via `composer run tests`
4. Write code and create a PR
## Mailing lists
- General help and development list: http://groups.google.com/group/functional-php
- Commit list: http://groups.google.com/group/functional-php-commits
## Thank you
- [Richard Quadling](https://github.com/RQuadling) and [Pierre Joye](https://github.com/pierrejoye) for Windows build
help
- [David Soria Parra](https://github.com/dsp) for various ideas and the userland version of `Functional\flatten()`
- [Max Beutel](https://github.com/maxbeutel) for `Functional\unique()`, `Functional\invoke_first()`,
`Functional\invoke_last()` and all the discussions
- [An Phan](https://github.com/phanan) for [many](https://github.com/lstrojny/functional-php/pulls?q=author%3Aphanan)
great contributions