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:
parent
fbbe94bfa8
commit
5b368602fe
3 changed files with 39 additions and 3 deletions
|
|
@ -45,6 +45,8 @@ To have a consistent experience across all packages, some public interfaces have
|
||||||
|
|
||||||
### Changed
|
### 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
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- **request.result:** Correct the namespace in the `Prelude` doc comment (`Geekeey.Extensions.Result` → `Geekeey.Request.Result`)
|
- **request.result:** Correct the namespace in the `Prelude` doc comment (`Geekeey.Extensions.Result` → `Geekeey.Request.Result`)
|
||||||
|
|
|
||||||
|
|
@ -190,6 +190,26 @@ internal sealed class ResultEqualityTests
|
||||||
await Assert.That(success.GetHashCode()).IsNotEqualTo(failure.GetHashCode());
|
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]
|
[Test]
|
||||||
public async Task I_can_equal_non_generic_result_and_get_true_for_success_and_success()
|
public async Task I_can_equal_non_generic_result_and_get_true_for_success_and_success()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,15 @@ namespace Geekeey.Request.Result;
|
||||||
|
|
||||||
public partial class Result : IEquatable<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]
|
[Pure]
|
||||||
public bool Equals(Result? other)
|
public bool Equals(Result? other)
|
||||||
{
|
{
|
||||||
|
|
@ -49,7 +57,8 @@ public partial class Result : IEquatable<Result>
|
||||||
public partial class Result : IEqualityOperators<Result, Result, bool>
|
public partial class Result : IEqualityOperators<Result, Result, bool>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
/// <param name="a">The first result to compare.</param>
|
/// <param name="a">The first result to compare.</param>
|
||||||
/// <param name="b">The second 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
|
/// 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.
|
/// the success values are equal, or if both results are failures.
|
||||||
/// </summary>
|
/// </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>
|
/// <param name="other">The result to check for equality with the current result.</param>
|
||||||
[Pure]
|
[Pure]
|
||||||
public bool Equals(Result<T>? other)
|
public bool Equals(Result<T>? other)
|
||||||
|
|
@ -194,7 +208,7 @@ public partial class Result<T> : IEqualityOperators<Result<T>, Result<T>, bool>,
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks whether two results are equal. Results are equal if both results are success values and the success
|
/// 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>
|
/// </summary>
|
||||||
/// <param name="a">The first result to compare.</param>
|
/// <param name="a">The first result to compare.</param>
|
||||||
/// <param name="b">The second result to compare.</param>
|
/// <param name="b">The second result to compare.</param>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue