-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #735 from polyadic/inspect-left
- Loading branch information
Showing
8 changed files
with
124 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using Xunit.Sdk; | ||
|
||
namespace Funcky.Test.Monads; | ||
|
||
public sealed partial class OptionTest | ||
{ | ||
[Fact] | ||
public void InspectNoneDoesNothingWhenOptionIsNone() | ||
{ | ||
var option = Option.Some(10); | ||
option.InspectNone(() => throw new XunitException("Side effect was unexpectedly called")); | ||
} | ||
|
||
[Fact] | ||
public void InspectNoneCallsSideEffectWhenOptionIsNone() | ||
{ | ||
var option = Option<int>.None; | ||
|
||
var sideEffect = false; | ||
option.InspectNone(() => sideEffect = true); | ||
Assert.True(sideEffect); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(SomeAndNone))] | ||
public void InspectLeftReturnsOriginalValue(Option<int> option) | ||
{ | ||
Assert.Equal(option, option.InspectNone(NoOperation)); | ||
} | ||
|
||
public static TheoryData<Option<int>> SomeAndNone() | ||
=> new() | ||
{ | ||
Option<int>.None, | ||
Option.Some(42), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Xunit.Sdk; | ||
|
||
namespace Funcky.Test.Monads; | ||
|
||
public sealed partial class ResultTest | ||
{ | ||
[Fact] | ||
public void InspectErrorDoesNothingWhenResultIsOk() | ||
{ | ||
var result = Result.Ok("foo"); | ||
result.InspectError(_ => throw new XunitException("Side effect was unexpectedly called")); | ||
} | ||
|
||
[Fact] | ||
public void InspectErrorCallsSideEffectWhenResultIsError() | ||
{ | ||
var exception = new Exception("Bam!"); | ||
var result = Result<string>.Error(exception); | ||
|
||
var sideEffect = Option<Exception>.None; | ||
result.InspectError(v => sideEffect = v); | ||
FunctionalAssert.Some(exception, sideEffect); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(OkAndError))] | ||
public void InspectErrorReturnsOriginalValue(Result<int> result) | ||
{ | ||
Assert.Equal(result, result.InspectError(NoOperation)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
#nullable enable | ||
Funcky.Monads.Either<TLeft, TRight>.InspectLeft(System.Action<TLeft>! inspector) -> Funcky.Monads.Either<TLeft, TRight> | ||
Funcky.Monads.Either<TLeft, TRight>.OrElse(Funcky.Monads.Either<TLeft, TRight> fallback) -> Funcky.Monads.Either<TLeft, TRight> | ||
Funcky.Monads.Either<TLeft, TRight>.OrElse(System.Func<TLeft, Funcky.Monads.Either<TLeft, TRight>>! fallback) -> Funcky.Monads.Either<TLeft, TRight> | ||
Funcky.Monads.Option<TItem>.InspectNone(System.Action! inspector) -> Funcky.Monads.Option<TItem> | ||
Funcky.Monads.Result<TValidResult>.GetOrElse(System.Func<System.Exception!, TValidResult>! fallback) -> TValidResult | ||
Funcky.Monads.Result<TValidResult>.GetOrElse(TValidResult fallback) -> TValidResult | ||
Funcky.Monads.Result<TValidResult>.InspectError(System.Action<System.Exception!>! inspector) -> Funcky.Monads.Result<TValidResult> | ||
Funcky.Monads.Result<TValidResult>.OrElse(Funcky.Monads.Result<TValidResult> fallback) -> Funcky.Monads.Result<TValidResult> | ||
Funcky.Monads.Result<TValidResult>.OrElse(System.Func<System.Exception!, Funcky.Monads.Result<TValidResult>>! fallback) -> Funcky.Monads.Result<TValidResult> |