loper / munus
结合面向对象编程的力量与函数式编程的优雅。
v0.5.0
2023-09-15 12:51 UTC
Requires
- php: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.9
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^8.4
This package is auto-updated.
Last update: 2024-09-15 14:52:52 UTC
README
结合面向对象编程的力量与函数式编程的优雅。通过减少代码量来提高健壮性。
目前处于实验阶段。
由于缺乏泛型,Munus通过PHPStan 模板
注解实现泛型。
流示例:查找前十个偶数的平方和
Stream::from(1) ->filter(fn($n) => $n%2===0) ->map(fn($n) => $n**2) ->take(10) ->sum();
其他示例
/** @var Stream<int> $stream */ $stream = Stream::range(1, 10)->map(function(int $int): int {return $int * 5}); /** @var Option<Success> $option */ $option = Option::of(domainOperation()); /** @return Either<Failure,Success> */ function domainOperation(): Either {} /** @var TryTo<Result> $result */ $result = TryTo::run(function(){throw new \DomainException('use ddd');}); $result->getOrElse(new Result())
目标是帮助实现:Psalm能够为100%的代码库推断类型
功能
值
- TryTo
- Either
- Option
- Lazy
集合
- 集合
- 流(实现为惰性链接列表)
- GenericList(实现为不可变链接列表)
- 迭代器
其他
- 元组
路线图
- 模式匹配
- 属性检查
灵感
这个库受vavr.io的启发。
许可证
Munus在MIT许可证下发布。有关详细信息,请参阅附带的LICENSE文件。