Skip to content

Instantly share code, notes, and snippets.

@refactorsaurusrex
Created May 22, 2016 20:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save refactorsaurusrex/4a9136bb2ed128fdaf0182626ca94551 to your computer and use it in GitHub Desktop.
Save refactorsaurusrex/4a9136bb2ed128fdaf0182626ca94551 to your computer and use it in GitHub Desktop.
Maybe<T>, inspired by Mark Seemann
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