Created
May 22, 2016 20:46
-
-
Save refactorsaurusrex/4a9136bb2ed128fdaf0182626ca94551 to your computer and use it in GitHub Desktop.
Maybe<T>, inspired by Mark Seemann
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 class Maybe<T> : IEnumerable<T> | |
{ | |
readonly IEnumerable<T> values; | |
public Maybe() | |
{ | |
values = new T[0]; | |
} | |
public Maybe(T value) | |
{ | |
values = new[] { value }; | |
} | |
public IEnumerator<T> GetEnumerator() | |
{ | |
return values.GetEnumerator(); | |
} | |
IEnumerator IEnumerable.GetEnumerator() | |
{ | |
return GetEnumerator(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment