-
-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Louth
committed
Jul 16, 2021
1 parent
7644dc2
commit 652f38f
Showing
12 changed files
with
281 additions
and
132 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System; | ||
using LanguageExt.Common; | ||
|
||
namespace LanguageExt | ||
{ | ||
public static partial class Prelude | ||
{ | ||
/// <summary> | ||
/// Catch an error if the predicate matches | ||
/// </summary> | ||
public static CatchValue<A> matchError<A>(Func<Error, bool> predicate, Func<Error, A> Fail) => | ||
new CatchValue<A>(predicate, Fail); | ||
|
||
/// <summary> | ||
/// Catch an error if the predicate matches | ||
/// </summary> | ||
public static CatchValue<A> matchError<A>(Func<Error, bool> predicate, A Fail) => | ||
matchError(predicate, _ => Fail); | ||
|
||
|
||
/// <summary> | ||
/// Catch an error if the error matches the argument provided | ||
/// </summary> | ||
public static CatchValue<A> match<A>(Error error, Func<Error, A> Fail) => | ||
matchError(e => e == error, Fail); | ||
|
||
/// <summary> | ||
/// Catch an error if the error matches the argument provided | ||
/// </summary> | ||
public static CatchValue<A> match<A>(Error error, A Fail) => | ||
matchError(e => e == error, _ => Fail); | ||
|
||
|
||
/// <summary> | ||
/// Catch an error if the error `Code` matches the `errorCode` argument provided | ||
/// </summary> | ||
public static CatchValue<A> match<A>(int errorCode, Func<Error, A> Fail) => | ||
matchError(e => e.Code == errorCode, Fail); | ||
|
||
/// <summary> | ||
/// Catch an error if the error `Code` matches the `errorCode` argument provided | ||
/// </summary> | ||
public static CatchValue<A> match<A>(int errorCode, A Fail) => | ||
matchError(e => e.Code == errorCode, _ => Fail); | ||
|
||
|
||
/// <summary> | ||
/// Catch an error if the error message matches the `errorText` argument provided | ||
/// </summary> | ||
public static CatchValue<A> match<A>(string errorText, Func<Error, A> Fail) => | ||
matchError(e => e.Message == errorText, Fail); | ||
|
||
/// <summary> | ||
/// Catch an error if the error message matches the `errorText` argument provided | ||
/// </summary> | ||
public static CatchValue<A> match<A>(string errorText, A Fail) => | ||
matchError(e => e.Message == errorText, _ => Fail); | ||
|
||
|
||
/// <summary> | ||
/// Catch an error if it's of a specific exception type | ||
/// </summary> | ||
public static CatchValue<A> match<A>(Func<Exception, bool> predicate, Func<Exception, A> Fail) => | ||
matchError(e => e.Exception.Map(predicate).IfNone(false), e => Fail(e.ToException())); | ||
|
||
/// <summary> | ||
/// Catch an error if it's of a specific exception type | ||
/// </summary> | ||
public static CatchValue<A> match<A>(Func<Exception, bool> predicate, A Fail) => | ||
matchError(e => e.Exception.Map(predicate).IfNone(false), e => Fail); | ||
} | ||
} |
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
Oops, something went wrong.