docs(result): document that failure equality ignores error content

Result/Result<T> equality treats any two failures as equal regardless of their
Error, which was undocumented and surprising for failure-specific branching.
This commit is contained in:
Louis Seubert 2026-07-12 18:35:50 +02:00
commit ab9407085d
Signed by: louis9902
GPG key ID: 4B9DB28F826553BD
3 changed files with 39 additions and 3 deletions

View file

@ -45,6 +45,8 @@ To have a consistent experience across all packages, some public interfaces have
### Changed
- **request.result:** Document that `Result`/`Result<T>` equality treats any two failures as equal, ignoring error content; branch on the `Error` directly for failure-specific logic (see PLAN.md Inconsistencies#E)
### Fixed
- **request.result:** Correct the namespace in the `Prelude` doc comment (`Geekeey.Extensions.Result``Geekeey.Request.Result`)

View file

@ -190,6 +190,26 @@ internal sealed class ResultEqualityTests
await Assert.That(success.GetHashCode()).IsNotEqualTo(failure.GetHashCode());
}
[Test]
public async Task I_can_equal_failure_and_failure_ignoring_error_content()
{
var a = Prelude.Failure<int>("error 1");
var b = Prelude.Failure<int>("error 2");
await Assert.That(a.Equals(b)).IsTrue();
await Assert.That(a.Error).IsNotEqualTo(b.Error);
}
[Test]
public async Task I_can_equal_non_generic_failure_and_failure_ignoring_error_content()
{
var a = Prelude.Failure("error 1");
var b = Prelude.Failure("error 2");
await Assert.That(a.Equals(b)).IsTrue();
await Assert.That(a.Error).IsNotEqualTo(b.Error);
}
[Test]
public async Task I_can_equal_non_generic_result_and_get_true_for_success_and_success()
{

View file

@ -9,7 +9,15 @@ namespace Geekeey.Request.Result;
public partial class Result : IEquatable<Result>
{
/// <inheritdoc/>
/// <summary>
/// Checks whether two results are equal. Results are equal if both are success or both are failure.
/// </summary>
/// <remarks>
/// Two failures are considered equal regardless of their <see cref="Error"/> content. Equality therefore
/// ignores the error; if you need to branch on a specific failure, compare the <see cref="Error"/> values
/// directly instead of relying on equality.
/// </remarks>
/// <param name="other">The result to check for equality with the current result.</param>
[Pure]
public bool Equals(Result? other)
{
@ -49,7 +57,8 @@ public partial class Result : IEquatable<Result>
public partial class Result : IEqualityOperators<Result, Result, bool>
{
/// <summary>
/// Checks whether two results are equal. Results are equal if they are both success or both failure.
/// Checks whether two results are equal. Results are equal if they are both success or both failure. Two
/// failures are equal regardless of their error content.
/// </summary>
/// <param name="a">The first result to compare.</param>
/// <param name="b">The second result to compare.</param>
@ -79,6 +88,11 @@ public partial class Result<T> : IEquatable<Result<T>>, IEquatable<T>
/// Checks whether the result is equal to another result. Results are equal if both results are success values and
/// the success values are equal, or if both results are failures.
/// </summary>
/// <remarks>
/// Two failures are considered equal regardless of their <see cref="Error"/> content. Equality therefore
/// ignores the error; if you need to branch on a specific failure, compare the <see cref="Error"/> values
/// directly instead of relying on equality.
/// </remarks>
/// <param name="other">The result to check for equality with the current result.</param>
[Pure]
public bool Equals(Result<T>? other)
@ -194,7 +208,7 @@ public partial class Result<T> : IEqualityOperators<Result<T>, Result<T>, bool>,
{
/// <summary>
/// Checks whether two results are equal. Results are equal if both results are success values and the success
/// values are equal, or if both results are failures.
/// values are equal, or if both results are failures. Two failures are equal regardless of their error content.
/// </summary>
/// <param name="a">The first result to compare.</param>
/// <param name="b">The second result to compare.</param>