-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-Authored-By: Thomas Bruderer <[email protected]>
- Loading branch information
1 parent
d0520b0
commit 52b5459
Showing
3 changed files
with
35 additions
and
0 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,19 @@ | ||
namespace Funcky; | ||
|
||
public static class Discard | ||
{ | ||
/// <summary>A convenient shortcut for getting a <see cref="Unit"/>. | ||
/// Useful for using switch expressions purely with guards when matching on non-constant values | ||
/// or as an alternative to <c>if</c> / <c>else if</c> / <c>else</c> chains.</summary> | ||
/// <example><code> | ||
/// using static Funcky.Discard; | ||
/// return __ switch | ||
/// { | ||
/// _ when user.IsFrenchAdmin() => "le sécret", | ||
/// _ when user.IsAdmin() => "secret", | ||
/// _ => "(redacted)", | ||
/// }; | ||
/// </code></example> | ||
/// <remarks>The name is intentionally two underscores as to not conflict with C#'s discard syntax.</remarks> | ||
public static readonly Unit __ = Unit.Value; | ||
} |
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