예제 #1
0
        //public static IOrType<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric> Broaden(this IOrType<MustHave, MustBePrimitive, GivenPathThen,  HasMembers, IsGenericRestraintFor, IsExternal> self) {
        //    return self.SwitchReturns(
        //        x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x),
        //        x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x),
        //        x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x),
        //        x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x),
        //        x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x),
        //        x => OrType.Make<MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric>(x));
        //}

        public static IOrType <IIsPossibly <Guid>, IError> Primitive(this EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > self)
        {
            var primitives = self.SelectMany(x =>
            {
                if (x.Is2(out var v2))
                {
                    return(new[] { v2 });
                }
                return(Array.Empty <MustBePrimitive>());
            }).ToArray();

            if (primitives.Length == self.Count())
            {
                var groupedPrimitives = primitives.GroupBy(x => x.primitive).ToArray();
                if (groupedPrimitives.Length == 1)
                {
                    return(OrType.Make <IIsPossibly <Guid>, IError>(Possibly.Is(groupedPrimitives.First().Key)));
                }
                return(OrType.Make <IIsPossibly <Guid>, IError>(Error.Other("multiple primitives types...")));
            }

            if (primitives.Any())
            {
                return(OrType.Make <IIsPossibly <Guid>, IError>(Error.Other("primitives and non primitives")));
            }
            return(OrType.Make <IIsPossibly <Guid>, IError>(Possibly.IsNot <Guid>()));
        }
예제 #2
0
        private static bool ErrorCheck(this EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > self, [NotNullWhen(true)] out IError?error)
        {
            if (self.Any(x => x.Is2(out var _)) && !self.All(x => x.Is2(out var _)))
            {
                error = Error.Other("primitives and non primitives");
                return(true);
            }

            if (self.Any(x => x.Is1(out var mustHave) && mustHave.path.Is1(out var _)) &&
                (
                    self.Any(x => x.Is1(out var mustHave) && mustHave.path.Is2(out var _) ||
                             self.Any(x => x.Is1(out var mustHave) && mustHave.path.Is3(out var _)))
                ))
            {
                error = Error.Other("is it a method or is it an object");
                return(true);
            }
            error = default;
            return(false);
        }
예제 #3
0
        public static IOrType <IReadOnlyList <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > >, IError> Generics(this EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > self)
        {
            if (self.ErrorCheck(out var error))
            {
                return(OrType.Make <IReadOnlyList <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > >, IError>(error));
            }

            var givenPathDictionary = self
                                      .SelectMany(x =>
            {
                if (x.Is3(out var v3))
                {
                    return(new[] { v3 });
                }
                return(Array.Empty <GivenPathThen>());
            })
                                      .Where(x => x.path.Is4(out var _))
                                      .GroupBy(x => x.path.Is4OrThrow()).ToDictionary(x => x.Key, x => x);

            var mustHaveGroup = self
                                .SelectMany(x =>
            {
                if (x.Is1(out var v1))
                {
                    return(new[] { v1 });
                }
                return(Array.Empty <MustHave>());
            })
                                .Where(x => x.path.Is4(out var _))
                                .GroupBy(x => x.path.Is4OrThrow());

            var pairs = new List <(int, EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >)>();

            foreach (var mustHaves in mustHaveGroup)
            {
                var set = new HashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >();

                //var extened = false;
                //{
                //    var sources = mustHaves.Select(x => x.dependent).ToHashSet();
                //    if (givenPathDictionary.TryGetValue(mustHaves.Key, out var givenPaths))
                //    {
                //        foreach (var givenPath in givenPaths)
                //        {
                //            sources.Add(givenPath.dependent);
                //        }
                //    }

                //    if (sources.Count() == 1)
                //    {
                //        extened = true;
                //    }
                //}

                foreach (var mustHave in mustHaves)
                {
                    foreach (var constraint in mustHave.dependent.GetExtendedConstraints())
                    {
                        set.Add(constraint);
                    }
                }
                {
                    if (givenPathDictionary.TryGetValue(mustHaves.Key, out var givenPaths))
                    {
                        foreach (var givenPath in givenPaths)
                        {
                            foreach (var constraint in givenPath.dependent.GetExtendedConstraints())
                            {
                                set.Add(constraint);
                            }
                        }
                    }
                }
                var equalableSet = new EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >(set);

                pairs.Add((mustHaves.Key.index, equalableSet));
            }

            if (!pairs.Any())
            {
                return(OrType.Make <IReadOnlyList <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > >, IError>(Array.Empty <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > >()));
            }

            if (pairs.Select(x => x.Item1).Max() != pairs.Count() - 1)
            {
                // I think this is an exception and not an IError
                // you really shouldn't be able to have disconunious generic constraints
                throw new Exception("the generic constriants are discontinious...");
            }

            return(OrType.Make <IReadOnlyList <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > >, IError>(pairs.OrderBy(x => x.Item1).Select(x => x.Item2).ToArray()));
        }
예제 #4
0
        public static IIsPossibly <IOrType <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >, IError> > Output(this EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > self)
        {
            if (self.ErrorCheck(out var error))
            {
                return(Possibly.Is(OrType.Make <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >, IError>(error)));
            }

            var mustHaves = self
                            .SelectMany(x =>
            {
                if (x.Is1(out var v1))
                {
                    return(new[] { v1 });
                }
                return(Array.Empty <MustHave>());
            })
                            .Where(x => x.path.Is3(out var _))
                            .ToArray();

            if (mustHaves.Any())
            {
                var set = new HashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >();


                var givenPaths = self
                                 .SelectMany(x =>
                {
                    if (x.Is3(out var v3))
                    {
                        return(new[] { v3 });
                    }
                    return(Array.Empty <GivenPathThen>());
                })
                                 .Where(x => x.path.Is3(out var _));

                //var extened = false;
                //{
                //    var sources = mustHaves.Select(x => x.dependent).ToHashSet();

                //    foreach (var givenPath in givenPaths)
                //    {
                //        sources.Add(givenPath.dependent);
                //    }

                //    if (sources.Count() == 1)
                //    {
                //        extened = true;
                //    }
                //}

                foreach (var mustHave in mustHaves)
                {
                    foreach (var constraint in mustHave.dependent.GetExtendedConstraints())
                    {
                        set.Add(constraint);
                    }
                }


                foreach (var givenPath in givenPaths)
                {
                    foreach (var constraint in  givenPath.dependent.GetExtendedConstraints())
                    {
                        set.Add(constraint);
                    }
                }
                return(Possibly.Is(OrType.Make <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >, IError>(new EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >(set))));
            }
            return(Possibly.IsNot <IOrType <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >, IError> >());
        }
예제 #5
0
        public static IOrType <ICollection <KeyValuePair <IKey, EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > > >, IError> PrivateMembers(this EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > self)
        {
            if (self.ErrorCheck(out var error))
            {
                return(OrType.Make <ICollection <KeyValuePair <IKey, EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > > >, IError>(error));
            }

            var givenPathDictionary = self
                                      .SelectMany(x =>
            {
                if (x.Is3(out var v3))
                {
                    return(new[] { v3 });
                }
                return(Array.Empty <GivenPathThen>());
            })
                                      .Where(x => x.path.Is5(out var _))
                                      .GroupBy(x => x.path.Is5OrThrow()).ToDictionary(x => x.Key, x => x);

            var mustHaveGroup = self
                                .SelectMany(x =>
            {
                if (x.Is1(out var v1))
                {
                    return(new[] { v1 });
                }
                return(Array.Empty <MustHave>());
            })
                                .Where(x => x.path.Is5(out var _))
                                .GroupBy(x => x.path.Is5OrThrow());

            var list = new List <KeyValuePair <IKey, EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > > >();

            foreach (var mustHaves in mustHaveGroup)
            {
                var set = new HashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >();

                foreach (var mustHave in mustHaves)
                {
                    foreach (var constraint in mustHave.dependent.GetExtendedConstraints())
                    {
                        set.Add(constraint);
                    }
                }
                {
                    if (givenPathDictionary.TryGetValue(mustHaves.Key, out var givenPaths))
                    {
                        foreach (var givenPath in givenPaths)
                        {
                            foreach (var constraint in givenPath.dependent.GetExtendedConstraints())
                            {
                                set.Add(constraint);
                            }
                        }
                    }
                }
                var equalableSet = new EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> >(set);

                list.Add(new KeyValuePair <IKey, EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > >(mustHaves.Key.key, equalableSet));
            }

            return(OrType.Make <ICollection <KeyValuePair <IKey, EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > > >, IError>(list));
        }
예제 #6
0
        // this is basically
        // A and B and (C or D) to (A and B and C) or (A and B and D)
        // returns OR AND
        public static EqualableHashSet <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > > Flatten(this EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, OrConstraint, HasMembers, IsGeneric, IsExternal> > self)
        {
            // AND OR AND
            var andOrAnd = self
                           .Where(x => x.Is4(out var _))
                           .Select(x => x.Is4OrThrow())
                           .Select(x => x.source.or
                                   // OR AND
                                   .SelectMany(y => y.GetValueAs(out IConstraintSoruce _).GetExtendedConstraints().Flatten())
                                   .ToArray())
                           .ToHashSet();

            var orAndRes = new List <List <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > >()
            {
                new List <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> >()
            };


            foreach (var orAnd in andOrAnd)
            {
                var nextOrAndRes = new List <List <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > >()
                {
                };

                foreach (var andRes in orAndRes)
                {
                    foreach (var and in orAnd)
                    {
                        if (andRes.All(andResItem => and.All(andItem => andResItem.GetValueAs(out IConstraint _).ExtendedIsCompatible(andItem))))
                        {
                            var list = andRes.ToList();
                            list.AddRange(and);
                            nextOrAndRes.Add(list);
                        }
                    }
                    orAndRes = nextOrAndRes;
                }
            }

            var shared = self.Where(x => !x.Is4(out var _))
                         .Select(x => x.SwitchReturns(
                                     y => OrType.Make <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal>(y),
                                     y => OrType.Make <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal>(y),
                                     y => OrType.Make <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal>(y),
                                     _ => throw new Exception("I just said not that!"),
                                     y => OrType.Make <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal>(y),
                                     y => OrType.Make <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal>(y),
                                     y => OrType.Make <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal>(y)))
                         .ToList();

            {
                var nextOrAndRes = new List <List <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > >()
                {
                };

                foreach (var andRes in orAndRes)
                {
                    if (andRes.All(andResItem => shared.All(sharedItem => andResItem.GetValueAs(out IConstraint _).ExtendedIsCompatible(sharedItem))))
                    {
                        andRes.AddRange(shared);
                        nextOrAndRes.Add(andRes);
                    }
                }
                orAndRes = nextOrAndRes;
            }

            return(new EqualableHashSet <EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> > >(
                       orAndRes.Select(x => new EqualableHashSet <IOrType <MustHave, MustBePrimitive, GivenPathThen, HasMembers, IsGeneric, IsExternal> >(x.ToHashSet())).ToHashSet()));
        }