Exemple #1
0
        public static Query RandomMember <T>(this VarList <T> list, Var <T> member)
        {
            var listLength  = new Var <int>();
            var randomIndex = new Var <int>();

            return(list.Length(listLength)
                   & Query.Random(listLength, randomIndex)
                   & list.Nth(randomIndex, member));
        }
Exemple #2
0
        public static Query Nth <T>(this VarList <T> list, Var <int> index, Var <T> element)
        {
            var head = new Var <T>();
            var tail = new VarList <T>();

            return(list <= (head, tail)
                   & ((head <= element & index <= 0)
                      | (() =>
            {
                var innerIndex = new Var <int>();

                return tail.Nth(innerIndex, element)
                & index <= innerIndex.Inc;
            })
                      ));
        }