public void Reverse()
        {
            RelationalList <T1, T2> ret = Reversed();

            X = ret.X;
            Y = ret.Y;
        }
        public static RelationalList <T1, T2> ToRelationalList <T1, T2>(this IEnumerable <T1> x, IEnumerable <T2> y)
        {
            RelationalList <T1, T2> ret = new RelationalList <T1, T2>();

            ret.X = x.ToList();
            ret.Y = y.ToList();
            return(ret);
        }
        public RelationalList <T1, T2> Reversed()
        {
            RelationalList <T1, T2> reversed = new RelationalList <T1, T2>(X, Y);

            reversed.X.Reverse();
            reversed.Y.Reverse();
            return(reversed);
        }
        public static RelationalList <T1, T2> ToRelationalList <T1, T2>(this IEnumerable <T1> x, Func <T1, T2> selector)
        {
            RelationalList <T1, T2> ret = new RelationalList <T1, T2>();

            ret.X = x.ToList();
            ret.Y = (from s in x select selector(s)).ToList();
            return(ret);
        }
        public RelationalList <TX, TY> ConvertTo <TX, TY>() where TX : T1 where TY : T2
        {
            RelationalList <TX, TY> rl = new RelationalList <TX, TY>();

            for (int i = 0; i < Count; i++)
            {
                rl.Add(new RelationalListPair <TX, TY>((TX)X[i], (TY)Y[i]));
            }
            return(rl);
        }
        public RelationalList <T1, T2> FromDictionary(Dictionary <T1, T2> d)
        {
            RelationalList <T1, T2> ret = new RelationalList <T1, T2>();

            foreach (KeyValuePair <T1, T2> kvp in d)
            {
                ret.Add(kvp.Key, kvp.Value);
            }
            return(ret);
        }
 public void RemoveRange(RelationalList <T1, T2> items)
 {
     foreach (RelationalListPair <T1, T2> p in items)
     {
         if (Contains(p))
         {
             Remove(p);
         }
     }
 }
        /// <summary>
        /// Exception thrown and new items removed if duplicates were added
        /// </summary>
        /// <param name="index"></param>
        /// <param name="items"></param>
        public void InsertRange(int index, RelationalList <T1, T2> items)
        {
            X.InsertRange(index, items.X);
            Y.InsertRange(index, items.Y);

            if (DuplicatesFound())
            {
                RemoveRange(items);
                throw new Exception("Cannot insert duplicate elements");
            }
        }
 public static bool Any <T1, T2>(this RelationalList <T1, T2> list, Func <T1, T2, Boolean> selector)
 {
     foreach (RelationalListPair <T1, T2> rp in list)
     {
         if (selector(rp.X, rp.Y))
         {
             return(true);
         }
     }
     return(false);
 }
        /// <summary>
        /// Exception thrown and new items removed if duplicates were added
        /// </summary>
        /// <param name="items"></param>
        public void AddRange(RelationalList <T1, T2> items)
        {
            X = X.Concat(items.X).ToList();
            Y = Y.Concat(items.Y).ToList();

            if (DuplicatesFound())
            {
                RemoveRange(items);
                throw new Exception("Duplicate RelationalListPairs found after AddRange()");
            }
        }
 public RelationalListEnumerator(RelationalList <T1, T2> rl)
 {
     RList = rl;
     index = -1;
 }
 public static bool Any <T1, T2>(this RelationalList <T1, T2> list) => list.X.Any();