承接 ustream/option 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ustream/option

Composer 安装命令:

composer require ustream/option

包简介

README 文档

README

This is a PHP interpretation of the Option type with monadic structure. We beleive that the tests document the behavior and even though the implementation is similar to php-option there are some important differences we need to highlight.

There is apply instead of map and flatMap

We found it useful, that the monadic computation may decide to return with an arbitrary type, that will be converted to an Option if necessary.

The rules for Some::apply is as follows:

  • If the return type is not an Option it will be wrapped in Some
  • If there is no return value (actually the return value is null) it will be translated to None
  • If the return type is an Option it will be passed through (the same as for flatMap)

Examples

Wrapping a non Option type:

$result = someMethodReturningAnOptionalString($params)
	->apply(
		function ($result) {
			return $result . ' is a string!';
		})
	->getOrElse('default');

No need to explicitly return with None:

$module = $dataMaybe
    ->apply(
		function ($data) {
			if (isset($data['moduleConfig'])) {
				if (count($data['moduleConfig']) == 1) {
					return key($data['moduleConfig']);
				} elseif (count($data['moduleConfig']) > 1) {
					return 'full';
				}
			}
		}
	)
	->getOrElse('unknown');

There is otherwise instead of orElse with LazyOption

We use None::otherwise as the mirror of Some::apply.

Examples

Combining apply and otherwise:

header(
    locate($_SERVER["DOCUMENT_URI"])
		->apply(
			function ($location) {
				statsdIncrement('302');
				return 'Location: ' . $location;
			}
		)
		->otherwise(
			function () {
				statsdIncrement('404');
			}
		)
		->getOrElse("HTTP/1.0 404 Not Found")
);

Creating a chain of fallback functions:

return Ustream\Option\None::create()
    ->otherwise($this->ustreamPicture($userId, $size))
	->otherwise($this->facebookPictureFromSession($facebookNetwork, $isSecureAccess))
	->getOrElse($this->naPicture($size));

统计信息

  • 总下载量: 96
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 30
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-03-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固