https://github.com/phrenotype/lambda
Converts functions to lambdas
https://github.com/phrenotype/lambda
curry currying function-application functional-programming lambda lambda-functions partial-application
Last synced: 14 days ago
JSON representation
Converts functions to lambdas
- Host: GitHub
- URL: https://github.com/phrenotype/lambda
- Owner: phrenotype
- License: mit
- Created: 2021-11-01T18:35:19.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2023-03-17T14:44:12.000Z (almost 3 years ago)
- Last Synced: 2025-08-11T01:29:38.618Z (5 months ago)
- Topics: curry, currying, function-application, functional-programming, lambda, lambda-functions, partial-application
- Language: PHP
- Homepage:
- Size: 10.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lambda




This is a library for converting both named and annonymous php functions into lambda expressions. This the allows them to be curried and partially applied.
## Install
`composer require phrenotype/lambda`
## Examples
#### With all parameters required
```php
$add = lambda(function($a, $b, $c){
return $a + $b + $c;
});
echo $add(4,5,2);
echo $add(4,5)(2);
echo $add(4)(5,2);
echo $add(4)(5)(2);
```
#### With optional parameters
This is a little bit tricky.
```php
$add = lambda(function($a, $b, $c=2){
return $a + $b + $c;
});
```
The key thing to remember is that once the numbers of arguments applied ***exactly matches*** the required number of arguments, It will return a result, not a lambda. So, in applying arguments, do not apply them curry style when dealing with optional parameters. Use partial application instead.
```php
echo $add(4,5,2); // Ok
echo $add(4)(5,2) // Ok
echo $add(4,5)(2); // Error
echo $add(4)(5)(2); //Error
```
## Contact
**Email** : paul.contrib@gmail.com