diff --git a/EasyMonads/Either/Either.cs b/EasyMonads/Either/Either.cs index 83cdab5..1729f95 100644 --- a/EasyMonads/Either/Either.cs +++ b/EasyMonads/Either/Either.cs @@ -159,7 +159,7 @@ private static void ValidateFunction(Func function) throw new ArgumentNullException(nameof(function)); } } - + private static void ValidateMatch(Func left, Func right) { if (left is null) @@ -173,6 +173,16 @@ private static void ValidateMatch(Func left, Func } } + private static void ValidateMatch(Func neither, Func left, Func right) + { + if (neither is null) + { + throw new ArgumentNullException(nameof(neither)); + } + + ValidateMatch(left, right); + } + public TResult Match(Func left, Func right, TResult neither) { ValidateMatch(left, right); @@ -187,6 +197,20 @@ public TResult Match(Func left, Func r #pragma warning restore CS8524 } + public TResult Match(Func left, Func right, Func neither) + { + ValidateMatch(neither, left, right); + +#pragma warning disable CS8524 + return _state switch + { + EitherState.Neither => neither(), + EitherState.Left => left(_left!), + EitherState.Right => right(_right!) + }; +#pragma warning restore CS8524 + } + public TResult Match(TResult leftOrNeither, Func right) { ValidateFunction(right);