wiz-develop / php-monad
📦 Implemented the concept of monads in functional programming in PHP.
Installs: 2 405
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/wiz-develop/php-monad
Requires
- php: >=8.3
Requires (Dev)
- phpstan/extension-installer: ^1.4
- phpstan/phpstan: ^1.12
- phpstan/phpstan-strict-rules: ^1.6
- phpunit/php-code-coverage: ^11.0
- phpunit/phpunit: ^11.3
- wiz-develop/php-cs-fixer-config: ^8.4
README
関数型プログラミングのモナド概念を PHP で実装したライブラリです。Rust の Option / Result 型に着想を得ています。
インストール
composer require wiz-develop/php-monad
使用例
Option
use WizDevelop\PhpMonad\Option; $name = Option\fromValue($user['name'] ?? null) ->map(fn($n) => strtoupper($n)) ->filter(fn($n) => strlen($n) > 0) ->unwrapOr('Anonymous');
Result
use WizDevelop\PhpMonad\Result; $result = Result\fromThrowable( fn() => json_decode($json, flags: JSON_THROW_ON_ERROR), fn($e) => "Parse error: {$e->getMessage()}" ); $data = $result->map(fn($d) => $d['key'])->unwrapOr(null);
ドキュメント
詳細なガイドと API リファレンスは ドキュメントサイト を参照してください。
要件
- PHP 8.3 以上
ライセンス
MIT License