- Notifications
You must be signed in to change notification settings - Fork37
⚡️ λ PHP functional library focused on simplicity and performance
License
Lambdish/phunctional
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Phunctional, because functional programming matters.
Lambdish's Phunctional is a little library that tries to bring to PHP some aspects of functional programing withutil high order functions andfunctions for manage iterables.
Phunctional is heavily inspired byClojure and some other PHP libraries likeiter,compose andfelpado.
The main principles that we have in mind developing this library are:
- A collection can be any iterable PHP object, arrays or generators
- Favor composition vs inheritance
- Be lazy when you can
- Avoid state, state is (usually) evil!
- Simplicity over easiness
- Break the above rules if it makes sense
All of this can be resumed with a word:Immutability.
To install it with composer:
composer require lambdish/phunctionalThe first is to import every function you're going to use, for example:
usefunctionLambdish\phunctional\map;
And then you'll be able to use it:
map(function ($number) {return$number +10; }, [1,2,3,4,5]);// => [11, 12, 13, 14, 15]
And do something more complex like:
usefunctionLambdish\Phunctional\pipe;useconstLambdish\Phunctional\{filter_null,reverse,first};$lastNonNullableValue =pipe(filter_null, reverse, first);$lastNonNullableValue(['first',null,'other','last non nullable',null,null]);// => "last non nullable"
Here we're using the provided constants, that acts like an alias for the functions full qualified namespace(and therefore, arecallable).
You can find the functions documentationhere.
About
⚡️ λ PHP functional library focused on simplicity and performance
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
