refactorsaurusrex
5/22/2016 - 8:46 PM

Maybe<T>, inspired by Mark Seemann

Maybe, 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();
    }
}