Example #1
0
 public static IOption <T> TryParse <T>(string str, ParserDelegate <T> parser) =>
 parser(str, out var perhapsResult) ? Some.Of(perhapsResult) : new None <T>();
Example #2
0
 public static IOption <TElem> TryKey <TKey, TElem>(TKey key, IDictionary <TKey, TElem> dict) =>
 dict.ContainsKey(key) ? Some.Of(dict[key]) : new None <TElem>();
Example #3
0
 public static IOption <T> FromMaybeNull <T>(T value) where T : class =>
 value != null?Some.Of(value) : new None <T>();
Example #4
0
 public static IOption <TElem> TryFind <TElem>(IEnumerable <TElem> values, Func <TElem, bool> predicate) =>
 values.Any(predicate) ? Some.Of(values.First(predicate)) : new None <TElem>();
Example #5
0
 public static IOption <T> FromNullable <T>(T?value) where T : struct =>
 value.HasValue ? Some.Of(value.Value) : new None <T>();