Skip to content

Commit

Permalink
made all the helpers to readonly record struct for performance boost.
Browse files Browse the repository at this point in the history
  • Loading branch information
md-redwan-hossain committed Jul 27, 2024
1 parent d99793c commit a92658f
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/SharpOutcome/Helpers/BadOutcome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace SharpOutcome.Helpers;
/// </summary>
/// <param name="Tag">The unique tag of the bad outcome.</param>
/// <param name="Reason">The reason for the bad outcome (optional).</param>
public record BadOutcome(BadOutcomeTag Tag, string? Reason = null) : IBadOutcome;

public readonly record struct BadOutcome(BadOutcomeTag Tag, string? Reason = null) : IBadOutcome;

/// <summary>
/// Represents a bad outcome.
/// </summary>
/// <typeparam name="TOutcomeTag">The type of the bad outcome.</typeparam>
/// <param name="Tag">The unique tag of the bad outcome.</param>
/// <param name="Reason">The reason for the bad outcome (optional).</param>
public record BadOutcome<TOutcomeTag>(TOutcomeTag Tag, string? Reason = null) : IBadOutcome<TOutcomeTag>;
public readonly record struct BadOutcome<TOutcomeTag>(TOutcomeTag Tag, string? Reason = null)
: IBadOutcome<TOutcomeTag>;
4 changes: 2 additions & 2 deletions src/SharpOutcome/Helpers/BadOutcomeWithPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SharpOutcome.Helpers;
/// <param name="Tag">The unique tag of the bad outcome.</param>
/// <param name="Payload">The payload that carries contextual data.</param>
/// <param name="Reason">The reason for the bad outcome (optional).</param>
public record BadOutcomeWithPayload<TPayload>(
public readonly record struct BadOutcomeWithPayload<TPayload>(
BadOutcomeTag Tag,
TPayload Payload,
string? Reason = null
Expand All @@ -21,7 +21,7 @@ public record BadOutcomeWithPayload<TPayload>(
/// <param name="Payload">The payload that carries contextual data.</param>
/// <typeparam name="TPayload">The type of the payload.</typeparam>
/// <param name="Reason">The reason for the bad outcome (optional).</param>
public record BadOutcomeWithPayload<TPayload, TOutcomeTag>(
public readonly record struct BadOutcomeWithPayload<TPayload, TOutcomeTag>(
TOutcomeTag Tag,
TPayload Payload,
string? Reason = null
Expand Down
2 changes: 1 addition & 1 deletion src/SharpOutcome/Helpers/Failed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ namespace SharpOutcome.Helpers;
/// <summary>
/// Represents a generalized bad outcome.
/// </summary>
public readonly record struct Failed;
public readonly record struct Failed(string? Reason = null);
6 changes: 3 additions & 3 deletions src/SharpOutcome/Helpers/GoodOutcome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ namespace SharpOutcome.Helpers;
/// </summary>
/// <param name="Tag">The unique tag of the good outcome.</param>
/// <param name="Reason">The reason for the good outcome (optional).</param>
public record GoodOutcome(GoodOutcomeTag Tag, string? Reason = null) : IGoodOutcome;

public readonly record struct GoodOutcome(GoodOutcomeTag Tag, string? Reason = null) : IGoodOutcome;

/// <summary>
/// Represents a good outcome.
/// </summary>
/// <typeparam name="TOutcomeTag">The type of the good outcome.</typeparam>
/// <param name="Tag">The unique tag of the good outcome.</param>
/// <param name="Reason">The reason for the good outcome (optional).</param>
public record GoodOutcome<TOutcomeTag>(TOutcomeTag Tag, string? Reason = null) : IGoodOutcome<TOutcomeTag>;
public readonly record struct GoodOutcome<TOutcomeTag>(TOutcomeTag Tag, string? Reason = null)
: IGoodOutcome<TOutcomeTag>;
4 changes: 2 additions & 2 deletions src/SharpOutcome/Helpers/GoodOutcomeWithPayload.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SharpOutcome.Helpers;
/// <typeparam name="TPayload">The type of the payload.</typeparam>
/// <param name="Payload">The payload that carries contextual data.</param>
/// <param name="Reason">The reason for the good outcome (optional).</param>
public record GoodOutcomeWithPayload<TPayload>(
public readonly record struct GoodOutcomeWithPayload<TPayload>(
GoodOutcomeTag Tag,
TPayload Payload,
string? Reason = null
Expand All @@ -21,7 +21,7 @@ public record GoodOutcomeWithPayload<TPayload>(
/// <typeparam name="TPayload">The type of the payload.</typeparam>
/// <param name="Payload">The payload that carries contextual data.</param>
/// <param name="Reason">The reason for the good outcome (optional).</param>
public record GoodOutcomeWithPayload<TPayload, TOutcomeTag>(
public readonly record struct GoodOutcomeWithPayload<TPayload, TOutcomeTag>(
TOutcomeTag Tag,
TPayload Payload,
string? Reason = null
Expand Down
2 changes: 1 addition & 1 deletion src/SharpOutcome/Helpers/Successful.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ namespace SharpOutcome.Helpers;
/// <summary>
/// Represents a generalized good outcome.
/// </summary>
public readonly record struct Successful;
public readonly record struct Successful(string? Reason = null);
4 changes: 2 additions & 2 deletions src/SharpOutcome/ValueOutcome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public bool TryPickBadOutcome([NotNullWhen(true)] out TBadOutcome? badOutcome)
/// Tries to pick the good outcome from the <see cref="ValueOutcome{TGoodOutcome, TBadOutcome}"/>.
/// </summary>
/// <param name="goodOutcome">When this method returns, contains the good outcome if it exists; otherwise, the default value.</param>
/// <param name="badOutcome">When this method returns, contains the bad outcome if the good outcome does not exists; otherwise, the default value.</param>
/// <param name="badOutcome">When this method returns, contains the bad outcome if the good outcome does not exist; otherwise, the default value.</param>
/// <returns><c>true</c> if the good outcome exists; otherwise, <c>false</c>.</returns>
public bool TryPickGoodOutcome([NotNullWhen(true)] out TGoodOutcome? goodOutcome,
[NotNullWhen(false)] out TBadOutcome? badOutcome)
Expand All @@ -156,7 +156,7 @@ public bool TryPickGoodOutcome([NotNullWhen(true)] out TGoodOutcome? goodOutcome
/// Tries to pick the bad outcome from the <see cref="ValueOutcome{TGoodOutcome, TBadOutcome}"/>.
/// </summary>
/// <param name="badOutcome">When this method returns, contains the bad outcome if it exists; otherwise, the default value.</param>
/// <param name="goodOutcome">When this method returns, contains the good outcome if the bad outcome does not exists; otherwise, the default value.</param>
/// <param name="goodOutcome">When this method returns, contains the good outcome if the bad outcome does not exist; otherwise, the default value.</param>
/// <returns><c>true</c> if the bad outcome exists; otherwise, <c>false</c>.</returns>
public bool TryPickBadOutcome([NotNullWhen(true)] out TBadOutcome? badOutcome,
[NotNullWhen(false)] out TGoodOutcome? goodOutcome)
Expand Down

0 comments on commit a92658f

Please sign in to comment.