Esempio n. 1
0
        static int Position <TKey> (TKey item, IList sequence, bool fromEnd, EqualityTest <TKey> test, int start, int end, Function1 <TKey> key)
        {
            if (fromEnd)
            {
                throw new NotImplementedException();
            }
            int count = 0;

            foreach (object element in sequence)
            {
                if (count < start)
                {
                    count += 1;
                    continue;
                }
                if (count >= end)
                {
                    break;
                }
                TKey ekey = key(element);
                if (test(item, ekey))
                {
                    return(count);
                }
                count += 1;
            }
            return(-1);
        }
Esempio n. 2
0
        static int Position(object item, Cons sequence, bool fromEnd, EqualityTest test, int start, int end, Function1 key)
        {
            if (fromEnd)
            {
                throw new NotImplementedException();
            }

            int answer = 0;

            while (true)
            {
                if (answer >= end)
                {
                    return(-1);
                }
                if (answer >= start &&
                    test(item, key(sequence.Car)))
                {
                    break;
                }

                answer  += 1;
                sequence = (Cons)sequence.Cdr;
            }
            return(answer);
        }
Esempio n. 3
0
        static int Position(object item, object sequence, bool fromEnd, EqualityTest test, int start, int end, Function1 key)
        {
            if (sequence == null)
            {
                return(-1);
            }
            Cons list = sequence as Cons;

            if (list != null)
            {
                return(Position(item, list, fromEnd, test, start, end, key));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 4
0
            public override bool Equals(object obj)
            {
                EqualityTest other = obj as EqualityTest;

                return(other == null ? false : Value == other.Value);
            }
 public ListDictionaryUsingEqualityTest(EqualityTest test)
 {
     this.test = test;
 }
Esempio n. 6
0
        static TItem Find <TItem, Tkey> (Tkey item, System.Collections.Generic.ICollection <TItem> sequence, bool fromEnd, EqualityTest <Tkey> test, int start, int end, Function1 <Tkey, TItem> key)
        {
            if (fromEnd)
            {
                throw new NotImplementedException();
            }
            int count = 0;

            foreach (TItem element in sequence)
            {
                if (count < start)
                {
                    count += 1;
                    continue;
                }
                if (count >= end)
                {
                    break;
                }
                Tkey ekey = key(element);
                if (test(item, ekey))
                {
                    return(element);
                }
                count += 1;
            }
            return(default(TItem));
        }