Created
February 12, 2018 14:02
-
-
Save jciechowski/03bc76a213f67dcecdc1e300963e3d55 to your computer and use it in GitHub Desktop.
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> | |
{ | |
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