Esempio n. 1
0
 /// <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>()
                               )));
 }
Esempio n. 2
0
 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));
 }
Esempio n. 4
0
        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> >());
        }
Esempio n. 5
0
        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>());