From f8bf5629a4535ff54074e22eca853a8d00f6053f Mon Sep 17 00:00:00 2001 From: Takuma Kajikawa Date: Tue, 7 Jul 2026 12:58:24 +0900 Subject: [PATCH 1/2] docs: fix broken and inaccurate README examples - The Basic Usage match() example used named arguments (ok:, err:) that do not match the actual parameter names ($ok_fn, $err_fn), so it fataled with "Unknown named parameter $ok". Use positional arguments so the example runs as written. - strlen("Something went wrong") is 20, not 19. - Drop the unused `use Valbeat\Result\Result;` import from the snippet. - Soften the "impossible to accidentally ignore errors" claim: PHP has no must-use enforcement, so describe what the type actually provides. Claude-Session: https://claude.ai/code/session_017XTM7pxbWPVNLV639i5WgK --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f28649f..4db0d4b 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A Result type implementation for PHP inspired by Rust's `Result` 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 @@ -23,16 +23,15 @@ 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 $message = $success->match( - ok: fn($value) => "Success: $value", - err: fn($error) => "Error: $error" + fn($value) => "Success: $value", + fn($error) => "Error: $error" ); echo $message; // "Success: 42" @@ -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 From 3d544d615dfeb41fd35e9dcbb393a7eb59db04c4 Mon Sep 17 00:00:00 2001 From: Takuma Kajikawa Date: Tue, 7 Jul 2026 13:36:34 +0900 Subject: [PATCH 2/2] docs: keep the named-argument match() example, sequenced after the rename PR Review feedback: rewriting the example to positional args and then back once #91 renames the parameters to ok/err is patch-then-revert churn on the same lines. Keep the named-argument form here and merge this PR after #91, which makes it valid. Claude-Session: https://claude.ai/code/session_017XTM7pxbWPVNLV639i5WgK --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4db0d4b..fab7b03 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,8 @@ $failure = new Err("Something went wrong"); // Pattern matching with the match() method $message = $success->match( - fn($value) => "Success: $value", - fn($error) => "Error: $error" + ok: fn($value) => "Success: $value", + err: fn($error) => "Error: $error" ); echo $message; // "Success: 42"