定制 prewk/option 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

prewk/option

最新稳定版本:4.1.0

Composer 安装命令:

composer require prewk/option

包简介

Option object for PHP inspired by Rust

README 文档

README

A PHP implementation of Rust's Option type with roughly the same API.

Version information

Version 4.x.x requires PHP 8.1+. Make sure you match the versions for this and the Result library if you use both.

Installation

composer require prewk/option

Usage

use Prewk\Option;
use Prewk\Option\{Some, None};

function findSomething(): Option {
    // ...
    if ($foundSomething) {
        return new Some($thing);
    } else {
        return new None;
    }
}

function findSomethingElse(): Result {
    // ...
    if ($foundSomething) {
        return new Some($thing);
    } else {
        return new None;
    }
}

// Fallback to value
$value = findSomething()->unwrapOr(null);

// Fallback to option and throw an exception if both fail
$value = findSomething()->or(findSomethingElse())->unwrap();

// Throw custom exception on missing thing (None)
$value = findSomething()->expect(new Exception("Oh noes!"));

License

MIT & Apache 2.0

统计信息

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

GitHub 信息

  • Stars: 47
  • Watchers: 3
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: (MIT or Apache-2.0) 67420c9edd2e916fa980aebce622879e0e1d5799
  • 更新时间: 2017-04-28