-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Fallible.Void type to specify a return type which returns nothing but can contain an error. Fallible.Void can only be created using the Fallible.Return property. * Add Fallible.Void type to specify a return type which returns nothing but can contain an error. Fallible.Void can only be created using the Fallible.Return property.
- Loading branch information
1 parent
af1d600
commit 242feee
Showing
6 changed files
with
69 additions
and
27 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
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,21 @@ | ||
using System.Runtime.CompilerServices; | ||
|
||
namespace Fallible; | ||
|
||
public static class Fallible | ||
{ | ||
public static Fallible<TResult> Try<TResult>(Func<TResult> action, [CallerArgumentExpression("action")] string expression = "") | ||
{ | ||
try | ||
{ | ||
var value = action(); | ||
return value; | ||
} | ||
catch (Exception e) | ||
{ | ||
return new Error($"{expression} threw {e.GetType().Name}: {e.Message}"); | ||
} | ||
} | ||
|
||
public static Fallible<Void> Return => new Void(); | ||
} |
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,6 @@ | ||
namespace Fallible; | ||
|
||
public class Void | ||
{ | ||
internal Void() { } | ||
} |
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