Skip to content

Instantly share code, notes, and snippets.

@jciechowski
Created February 12, 2018 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jciechowski/03bc76a213f67dcecdc1e300963e3d55 to your computer and use it in GitHub Desktop.
Save jciechowski/03bc76a213f67dcecdc1e300963e3d55 to your computer and use it in GitHub Desktop.
public class Maybe<T> : IEnumerable<T>
{
private 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();
}
}
public static class Maybe
{
public static Maybe<T> ToMaybe<T>(this T value)
{
return new Maybe<T>(value);
}
public static Maybe<T> Empty<T>()
{
return new Maybe<T>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment