aharisu/option 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

aharisu/option

最新稳定版本:1.3.0

Composer 安装命令:

composer require aharisu/option

包简介

PHP Option object like a Rust language

README 文档

README

Software License Software License Build Status Coverage Status Latest Version

Version information

It will work with both PHP 7.x and PHP 8.x.
Tested with the following PHP versions

  • 7.0
  • 7.1
  • 7.2
  • 7.3
  • 7.4
  • 8.0
  • 8.1
  • 8.2

Installation

composer require aharisu/option

Usage

// make some object
$some = some(1);

// make none object
$none = none();

if ($some->isSome()) {
    $v = $some->unwrap();
}
if ($none->isNone()) {
    //do something
}

if (null != $v = $some->tryUnwrap()) {
    //do something
    print_r($v);
}

$some->someThen(function ($v) {
    //do something
    print_r($v);
});

$v2 = $none->unwrapOr(2);
$k = 10;
$v3 = $none->unwrapOrElse(fn () => 2 * $k);

// true
if (some(1)->equals(1)) {
}
if (some(1)->equals(some(1))) {
}
// false
if (none()->equals(null)) {
}

// false and type mismatch warning
if (some(1)->equals(1.0)) {
}
// false and type mismatch warning
if (some(1)->equals('1')) {
}

Using class property

use aharisu\Option;

class ValueType
{
    /**
     * @param Option<string> $text
     * @param Option<int>    $value
     */
    public function __construct(
        public readonly int $id,
        public readonly Option $text,
        public readonly Option $value,
    ) {
    }
}

new ValueType(
    1,
    toOption('text'), //some
    toOption(null),   //none
);

License

Apache 2.0 & MIT

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2023-03-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固