Skip to content

Instantly share code, notes, and snippets.

@jciechowski
Created Feb 12, 2018
Embed
What would you like to do?
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