functional
所属分类:collect
开发工具:PHP
文件大小:0KB
下载次数:0
上传日期:2016-11-01 16:29:33
上 传 者:
sh-1993
说明: PHP函数编程无循环落后。移至,
(Functional Programming for PHP no loop behind. Moved to ,)
文件列表:
.editorconfig (251, 2016-07-04)
.scrutinizer.yml (448, 2016-07-04)
.travis.yml (172, 2016-07-04)
build.xml (4349, 2016-07-04)
composer.json (1919, 2016-07-04)
examples/ (0, 2016-07-04)
examples/pipe_native_funcs.php (977, 2016-07-04)
examples/range.php (354, 2016-07-04)
phpunit.xml.dist (1204, 2016-07-04)
src/ (0, 2016-07-04)
src/Collection.php (2865, 2016-07-04)
src/_.php (54, 2016-07-04)
src/always.php (255, 2016-07-04)
src/append.php (383, 2016-07-04)
src/compose.php (460, 2016-07-04)
src/concat.php (484, 2016-07-04)
src/deleteat.php (388, 2016-07-04)
src/diff.php (353, 2016-07-04)
src/drop.php (371, 2016-07-04)
src/dropwhile.php (609, 2016-07-04)
src/each.php (394, 2016-07-04)
src/equals.php (363, 2016-07-04)
src/filter.php (416, 2016-07-04)
src/flatten.php (427, 2016-07-04)
src/get.php (582, 2016-07-04)
src/getin.php (841, 2016-07-04)
src/gt.php (360, 2016-07-04)
src/gte.php (379, 2016-07-04)
src/has.php (317, 2016-07-04)
src/head.php (402, 2016-07-04)
src/hold.php (686, 2016-07-04)
src/id.php (220, 2016-07-04)
src/ifelse.php (583, 2016-07-04)
src/last.php (259, 2016-07-04)
src/lt.php (357, 2016-07-04)
src/lte.php (376, 2016-07-04)
src/map.php (328, 2016-07-04)
src/not.php (202, 2016-07-04)
... ...
Functional
----------
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/sergiors/functional/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/sergiors/functional/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/sergiors/functional/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/sergiors/functional/?branch=master)
[![Build Status](https://scrutinizer-ci.com/g/sergiors/functional/badges/build.png?b=master)](https://scrutinizer-ci.com/g/sergiors/functional/build-status/master)
Motivation
----------
I did create this project to explore **Functional Programming**.
**This project doesn't use any loop!**
Install
-------
```bash
composer require sergiors/functional "dev-master"
```
How to use
----------
```php
use Sergiors\Functional as F;
$addFourNumbers = funciton ($a, $b, $c, $d) {
return $a + $b + $c + $d;
};
$partialAddFourNumbers = F\partial($addFourNumbers);
$f = $partialAddFourNumbers(1, 2);
$g = $f(3);
echo $g(4); // => 10
```
You can hold native functions with `Sergiors\Funcional\hold`.
```php
use Sergiors\Functional as F;
$implode = F\hold('implode', ',');
echo $implode(['a', 'b']); // => a,b
// something more complex
$pipe = F\pipe(
F\hold('array_slice', F\_, 2),
F\hold('array_map', function ($x) {
return $x * 2;
}),
F\hold('implode', ',')
);
echo $pipe([10, 20, 30, 40, 50]); // => 60,80,100
```
`Sergiors\Functional\_` is the placeholder for payload. If you don't set the placeholder, the payload will be last argument.
Collection
----------
You can wrap an array with `Sergiors\Functional\Collection` to use fluent interface.
```php
use Sergiors\Functional\Collection;
$ls1 = new Collection([1, 2, 3, 4, 5, 6]);
$ls2 = $ls1->filter(function ($x) {
return $x > 2;
})->map(function ($x) {
return $x + 1;
});
print_r($ls1->toArray()); // => [1, 2, 3, 4, 5, 6]
print_r($ls2->toArray()); // => [4, 5, 6, 7]
```
API
---
All functions are automatically applied partial application.
```
always()
append()
compose()
concat()
diff()
drop()
each()
equals()
filter()
flatten()
get()
getin()
gt()
gte()
has()
head()
hold()
id()
ifelse()
last()
lt()
lte()
map()
not()
partial()
pipe()
prop()
prepend()
reduce()
sort()
tail()
take()
takewhile()
```
```
Collection::concat()
Collection::filter()
Collection::map()
Collection::each()
Collection::prepend()
Collection::append()
Collection::reduce()
Collection::count()
Collection::getIterator()
Collection::toArray()
```
License
-------
MIT
近期下载者:
相关文件:
收藏者: