Skip to content

Commit

Permalink
chore: Reformat with Resharpier
Browse files Browse the repository at this point in the history
  • Loading branch information
lsymds committed Nov 25, 2023
1 parent 678ae28 commit eec89da
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 42 deletions.
6 changes: 2 additions & 4 deletions src/Result/Nothing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
/// </summary>
public class Nothing
{
private Nothing()
{
}
private Nothing() { }

/// <summary>
/// Gets the singleton instance of the <see cref="Nothing"/> class.
/// </summary>
public static Nothing Instance { get; } = new Nothing();
}
}
28 changes: 14 additions & 14 deletions src/Result/Result`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace LSymds.Result;

/// <summary>
/// A monad representing either a successful result or an erroneous result.
/// A monad representing either a successful result or an erroneous result.
/// </summary>
/// <typeparam name="TSuccess">The type of the successful result's data.</typeparam>
/// <typeparam name="TError">The type of the erroneous result's error.</typeparam>
Expand All @@ -30,23 +30,23 @@ internal Result(TError erroneous)
IsError = true;
Error = erroneous;
}

/// <summary>
/// Gets the data when <see cref="IsSuccess"/> is true. Will return null if it is not.
/// </summary>
public TSuccess? Data { get; }

/// <summary>
/// Gets the error when <see cref="IsError"/> is true. Will return null if it is not.
/// </summary>
public TError? Error { get; }
public TError? Error { get; }

/// <summary>
/// Gets whether or not the result is a successful result.
/// </summary>
[MemberNotNullWhen(true, nameof(Data))]
public bool IsSuccess { get; }

/// <summary>
/// Gets whether or not the result is an erroneous result.
/// </summary>
Expand All @@ -61,7 +61,7 @@ internal Result(TError erroneous)
/// <typeparam name="TNewSuccess">The new type of the successful data value.</typeparam>
public Result<TNewSuccess, TError> Map<TNewSuccess>(Func<TSuccess, TNewSuccess> dataMapper)
{
return IsSuccess
return IsSuccess
? new Result<TNewSuccess, TError>(dataMapper(Data!))
: new Result<TNewSuccess, TError>(Error!);
}
Expand All @@ -81,14 +81,16 @@ public Result<TSuccess, TNewError> MapError<TNewError>(Func<TError, TNewError> e

/// <summary>
/// Unsafely extracts the value of <see cref="Data"/>, throwing an <see cref="InvalidOperationException"/> if
/// <see cref="IsSuccess"/> is false.
/// <see cref="IsSuccess"/> is false.
/// </summary>
/// <exception cref="InvalidOperationException">Thrown when <see cref="IsSuccess"/> is false.</exception>
public TSuccess Unwrap()
{
if (!IsSuccess)
{
throw new InvalidOperationException("Unable to retrieve Data value as Result is in an erroneous state.");
throw new InvalidOperationException(
"Unable to retrieve Data value as Result is in an erroneous state."
);
}

return Data!;
Expand All @@ -101,9 +103,7 @@ public TSuccess Unwrap()
/// <param name="or">The alternative value to return when <see cref="IsSuccess"/> is false.</param>
public TSuccess UnwrapOrElse(TSuccess or)
{
return IsSuccess
? Data
: or;
return IsSuccess ? Data : or;
}

/// <summary>
Expand All @@ -113,7 +113,7 @@ public TSuccess UnwrapOrElse(TSuccess or)
public static Result<TSuccess, TError> Successful(TSuccess success)
{
return new Result<TSuccess, TError>(success);
}
}

/// <summary>
/// Creates a <see cref="Result{TSuccess,TError}"/> in an erroneous state with the provided error.
Expand All @@ -123,4 +123,4 @@ public static Result<TSuccess, TError> Erroneous(TError error)
{
return new Result<TSuccess, TError>(error);
}
}
}
2 changes: 1 addition & 1 deletion test/Result.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
global using Xunit;
global using Xunit;
6 changes: 3 additions & 3 deletions test/Result.Tests/ResultCreationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void CreatesASuccessfulResult()
{
// Act.
var result = Result<Nothing, Exception>.Successful(Nothing.Instance);

// Assert.
result.IsSuccess.ShouldBeTrue();
result.IsError.ShouldBeFalse();
Expand All @@ -22,11 +22,11 @@ public void CreatesAnErroneousResult()
{
// Act.
var result = Result<Nothing, string>.Erroneous("Oh no.");

// Assert.
result.IsSuccess.ShouldBeFalse();
result.IsError.ShouldBeTrue();
result.Data.ShouldBeNull();
result.Error.ShouldBe("Oh no.");
}
}
}
10 changes: 5 additions & 5 deletions test/Result.Tests/ResultMapErrorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public void AppliesTheMappingResult_WhenTheExistingResultIsErroneous()
{
// Arrange.
var existingResult = Result<Nothing, string>.Erroneous("Oh no.");

// Act.
var newResult = existingResult.MapError(e => e.Length);

// Assert.
newResult.IsSuccess.ShouldBeFalse();
newResult.IsError.ShouldBeTrue();
Expand All @@ -25,14 +25,14 @@ public void LeavesTheDataUnchanged_WhenTheExistingResultIsSuccessful()
{
// Arrange.
var existingResult = Result<string, string>.Successful("Success");

// Act.
var newResult = existingResult.MapError(_ => "Oh no.");

// Assert.
newResult.IsSuccess.ShouldBeTrue();
newResult.IsError.ShouldBeFalse();
newResult.Data.ShouldBe("Success");
newResult.Error.ShouldBeNull();
}
}
}
10 changes: 5 additions & 5 deletions test/Result.Tests/ResultMapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public void AppliesTheMappingFunction_WhenTheExistingResultIsSuccessful()
{
// Arrange.
var existingResult = Result<Nothing, string>.Successful(Nothing.Instance);

// Act.
var result = existingResult.Map(_ => "Foo");

// Assert.
result.IsSuccess.ShouldBeTrue();
result.IsError.ShouldBeFalse();
Expand All @@ -25,14 +25,14 @@ public void LeavesTheErrorUnchanged_WhenTheExistingResultIsErroneous()
{
// Arrange.
var existingResult = Result<Nothing, string>.Erroneous("Oh no.");

// Act.
var result = existingResult.Map(_ => "Foo");

// Assert.
result.IsSuccess.ShouldBeFalse();
result.IsError.ShouldBeTrue();
result.Data!.ShouldBeNull();
result.Error.ShouldBe("Oh no.");
}
}
}
10 changes: 5 additions & 5 deletions test/Result.Tests/ResultUnwrapOrElseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public void ReturnsTheValueOfData_WhenTheResultIsSuccessful()
{
// Arrange.
var result = Result<string, int>.Successful("Success");

// Act.
var value = result.UnwrapOrElse("Or");

// Assert.
value.ShouldBe("Success");
}
Expand All @@ -22,11 +22,11 @@ public void ReturnsTheAlternativeValue_WhenTheResultIsErroneous()
{
// Arrange.
var result = Result<string, int>.Erroneous(10);

// Act.
var value = result.UnwrapOrElse("Or");

// Assert.
value.ShouldBe("Or");
}
}
}
10 changes: 5 additions & 5 deletions test/Result.Tests/ResultUnwrapTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ public void ReturnsTheValueOfData_WhenTheResultIsSuccessful()
{
// Arrange.
var result = Result<string, int>.Successful("Success");

// Act.
var value = result.Unwrap();

// Assert.
value.ShouldBe("Success");
}
Expand All @@ -22,11 +22,11 @@ public void ThrowsAnException_WhenTheResultIsErroneous()
{
// Arrange.
var result = Result<string, int>.Erroneous(10);

// Act.
var func = () => result.Unwrap();

// Assert.
func.ShouldThrow<InvalidOperationException>();
}
}
}

0 comments on commit eec89da

Please sign in to comment.