Last active
October 11, 2017 20:50
-
-
Save einarwh/0df548e1496d561242ab659d2b3841af to your computer and use it in GitHub Desktop.
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
public abstract class Mayhaps<T> | |
{ | |
private Mayhaps() { } | |
public abstract bool HasValue { get; } | |
public abstract T Value { get; } | |
private class MayhapsIndeed : Mayhaps<T> | |
{ | |
private readonly T _value; | |
public MayhapsIndeed(T value) | |
{ | |
_value = value; | |
} | |
public override bool HasValue => true; | |
public override T Value => _value; | |
} | |
private class MayhapsSorry : Mayhaps<T> | |
{ | |
public override bool HasValue => false; | |
public override T Value | |
{ | |
get { throw new InvalidOperationException("Nothing here."); } | |
} | |
} | |
private static MayhapsSorry _sorry = new MayhapsSorry(); | |
public static Mayhaps<T> Indeed(T value) => | |
new MayhapsIndeed(value); | |
public static Mayhaps<T> Sorry => _sorry; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment