/// <summary> /// Retuns the current option only if its value matches the specified predicate. Otherwise returns an empty option. /// </summary> public static IOption <A> Where <A>(this IOption <A> option, Func <A, bool> predicate) { return(option.FlatMap(a => predicate(a).Match( t => option, f => Option.Empty <A>() ))); }
public static IOption <string> ToNonEmptyOption(this string s) { if (String.IsNullOrEmpty(s)) { return(Option.Empty <string>()); } return(s.ToOption()); }
public static IOption <V> Get <K, V>(this IReadOnlyDictionary <K, V> dictionary, K key) { if (Equals(key, null)) { return(Option.Empty <V>()); } return(Tryer.Invoke <K, V>(dictionary.TryGetValue, key)); }
static TotalOrder() { var defaultBound = IntervalBound.Open(default(A)).ToOption(); var noBound = Option.Empty <IntervalBound <A> >(); emptyInterval = new Interval <A>(defaultBound, defaultBound, isEmpty: true); unbounedInterval = new Interval <A>(noBound, noBound, isEmpty: false); emptyIntervalSet = new IntervalSet <A>(Enumerable.Empty <Interval <A> >()); }
public static IOption <TEnum> ToEnum <TEnum>(this string s, bool ignoreCase = false) where TEnum : struct { if (s == null || s.Contains(",")) { return(Option.Empty <TEnum>()); } var enumValue = Tryer.Invoke <string, bool, TEnum>(Enum.TryParse <TEnum>, s, ignoreCase); return(enumValue.Where(v => Enum.IsDefined(typeof(TEnum), v) && v.ToString().Equals(s, StringComparison.InvariantCultureIgnoreCase))); }
public static Monad.Reader <Environment, Task <ApiResult <SignUpResponse> > > Post(SignUpRequest request) => Post <SignUpRequest, SignUpResponse>(request, "/signUp", Option.Empty <AccessToken>());