coderofsalvation / microfunctional
最基本的函数式编程助手
dev-master
2020-05-28 19:17 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-09-20 18:30:36 UTC
README
最基本的函数式编程助手
- curry
- compose
- filter
- fold
- either
参见 此视频
用法
$ composer require coderofsalvation/microfunctional
然后
<?php
/*
* simple datastore example
*/
$createDefaultItem = function($key){
return (object)array("title" => $key);
};
$set = function($store,$key,$value){
$store->$key = $value;
};
$get = function($store,$key){
return isset($store->$key) ? $store->$key : false;
};
/*
* highorder functions using curry
*/
$store = (object)array();
$getFromStore = curry( $get,$store);
$saveToStore = curry( $set,$store);
$saveToStore("foo","bar");
print_r( $getFromStore("foo") );
?>
许可
BSD