コード例 #1
0
 public static FSharpOption <R> Join <T, I, K, R>(this FSharpOption <T> option, FSharpOption <I> inner, Func <T, K> outerKeySelector, Func <I, K> innerKeySelector, Func <T, I, R> resultSelector)
 {
     return(Lift(resultSelector)(option, inner));
 }
コード例 #2
0
 /// <summary>
 /// Gets a value indicating whether the current <see cref="FSharpOption{T}"/> object has a value
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="option"></param>
 /// <returns>true if the current <see cref="FSharpOption{T}"/> object has a value; false if the current <see cref="FSharpOption{T}"/> object has no value</returns>
 public static bool HasValue <T>(this FSharpOption <T> option)
 {
     return(FSharpOption <T> .get_IsSome(option));
 }
コード例 #3
0
        public static FSharpOption <IVersionSpec> ParseVersionSpec(string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }
            value = value.Trim();
            var checkLength =
                L.F((string val) => val.Length < 3 ? FSharpOption <Unit> .None : FSharpOption.SomeUnit);
            var minInclusive = L.F((string val) => {
                var c = val.First();
                if (c == '[')
                {
                    return(true.ToOption());
                }
                if (c == '(')
                {
                    return(false.ToOption());
                }
                return(FSharpOption <bool> .None);
            });
            var maxInclusive = L.F((string val) => {
                var c = val.Last();
                if (c == ']')
                {
                    return(true.ToOption());
                }
                if (c == ')')
                {
                    return(false.ToOption());
                }
                return(FSharpOption <bool> .None);
            });
            var checkParts =
                L.F((string[] parts) => parts.Length > 2 ? FSharpOption <Unit> .None : FSharpOption.SomeUnit);
            var minVersion = L.F((string[] parts) => {
                if (string.IsNullOrWhiteSpace(parts[0]))
                {
                    return(FSharpOption <FSharpOption <Version> > .Some(FSharpOption <Version> .None));
                }
                return(ParseVersion(parts[0]).Select(v => v.ToOption()));
            });
            var maxVersion = L.F((string[] parts) => {
                var p = parts.Length == 2 ? parts[1] : parts[0];
                if (string.IsNullOrWhiteSpace(p))
                {
                    return(FSharpOption <FSharpOption <Version> > .Some(FSharpOption <Version> .None));
                }
                return(ParseVersion(p).Select(v => v.ToOption()));
            });

            var singleVersion =
                from v in ParseVersion(value)
                select(IVersionSpec) new VersionSpec {
                IsMinInclusive = true, MinVersion = v
            };

            var versionRange = L.F(() => from x in checkLength(value)
                                   from isMin in minInclusive(value)
                                   from isMax in maxInclusive(value)
                                   let val                         = value.Substring(1, value.Length - 2)
                                                         let parts = val.Split(',')
                                                                     from y in checkParts(parts)
                                                                     from min in minVersion(parts)
                                                                     from max in maxVersion(parts)
                                                                     select(IVersionSpec) new VersionSpec {
                IsMinInclusive = isMin,
                MinVersion     = min.HasValue() ? min.Value : null,
                IsMaxInclusive = isMax,
                MaxVersion     = max.HasValue() ? max.Value : null,
            });

            return(singleVersion.OrElse(versionRange)());
        }