Esempio n. 1
0
 internal Enumerator(SingleList <T> singleList)
 {
     _list        = singleList;
     _index       = 0;
     _currentNode = null;
     _nextNode    = _list.head;
 }
Esempio n. 2
0
 /// <summary>
 /// There are three scnarios, advancing from 0 to 1
 /// From 1 to 2, 3, 5, i.e. regular
 /// Reaching the end of the collection, after which reset needs to be called;
 /// </summary>
 /// <returns></returns>
 public bool MoveNext()
 {
     if (_nextNode == null)
     {
         return(false);  //End of collection reached
     }
     _currentNode = _nextNode;
     _nextNode    = _nextNode.Next;
     _index++;
     return(true);
 }
Esempio n. 3
0
        private static IEnumerable <TResult> SelectMany <TSource, TResult>(this SingleList <TSource> list,
                                                                           Func <TSource, IEnumerable <TResult> > selector)
        {
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            //Create a function that just discards the index and calls the selector
            Func <TSource, int, IEnumerable <TResult> > selectorWithIterator = (i, n) => selector(i);

            return(SelectMany(list, selectorWithIterator));
        }
Esempio n. 4
0
        public static IEnumerable <TSource> Where <TSource>(this SingleList <TSource> list,
                                                            Predicate <TSource> predicate)
        {
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            //Create a function that just discards the index and calls the selector
            Func <TSource, int, bool> selectorWithIterator = (item, n) => predicate(item);

            return(Where(list, selectorWithIterator));
        }
Esempio n. 5
0
        private static IEnumerable <TResult> SelectMany <TSource, TResult>(this SingleList <TSource> list,
                                                                           Func <TSource, int, IEnumerable <TResult> > selector)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }
            if (selector == null)
            {
                throw new ArgumentNullException(nameof(selector));
            }

            int i = 0;

            foreach (TSource element in list)
            {
                foreach (TResult subElement in selector(element, i))
                {
                    yield return(subElement);
                }
                i++;
            }
        }
Esempio n. 6
0
        public static IEnumerable <TSource> Where <TSource>(this SingleList <TSource> list,
                                                            Func <TSource, int, bool> predicate)
        {
            if (list == null)
            {
                throw new ArgumentNullException(nameof(list));
            }
            if (predicate == null)
            {
                throw new ArgumentNullException(nameof(predicate));
            }

            int i = 0;

            foreach (TSource element in list)
            {
                if (predicate(element, i))
                {
                    yield return(element);
                }
                i++;
            }
        }
Esempio n. 7
0
 public void Reset()
 {
     _index       = 0;
     _currentNode = null;
     _nextNode    = _list.head;
 }