Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

A Result type implementation for PHP inspired by Rust's `Result<T, E>` type.

This library provides a robust way to handle operations that might fail, without relying on exceptions. It encourages explicit error handling and makes it impossible to accidentally ignore errors.
This library provides a robust way to handle operations that might fail, without relying on exceptions. It encourages explicit error handling by making the error case part of the return type, so failures are visible in function signatures instead of being hidden control flow.

## Installation

Expand All @@ -23,13 +23,12 @@ composer require valbeat/result
```php
use Valbeat\Result\Ok;
use Valbeat\Result\Err;
use Valbeat\Result\Result;

// Creating Results
$success = new Ok(42);
$failure = new Err("Something went wrong");

// Pattern matching with match expression
// Pattern matching with the match() method

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

match() メソッドによる分岐は、厳密な意味での「パターンマッチング(Pattern matching)」とは異なり、単に成功時と失敗時のコールバック関数を適用する処理(Catamorphism / Fold)です。PHPには言語機能として match 式が存在するため、読者がそれと混同する可能性があります。\n\nより正確に Handling results with the match() methodBranching with the match() method と表現することを提案します。

Suggested change
// Pattern matching with the match() method
// Handling results with the match() method

$message = $success->match(
ok: fn($value) => "Success: $value",
err: fn($error) => "Error: $error"
Expand All @@ -51,7 +50,7 @@ $value = $success->unwrap(); // 42

// Safe unwrapping with default values
$value = $failure->unwrapOr(0); // 0
$value = $failure->unwrapOrElse(fn($err) => strlen($err)); // 19
$value = $failure->unwrapOrElse(fn($err) => strlen($err)); // 20
```

## Advanced Usage
Expand Down
Loading