public HeadTailList(T head) { _hasHead = true; _head = head; _tail = null; Count = 1; }
public HeadTailList(T head, HeadTailList <T> tail) { _hasHead = true; _head = head; _tail = tail == null || tail.IsEmpty ? null : tail; Count = 1 + (tail?.Count ?? 0); }
private static T[] ToArray(HeadTailList <T> list, T[] array, int currentIndex) { if (!list._hasHead) { return(array); } array[currentIndex] = list._head; if (!(list._tail?._hasHead ?? false)) { return(array); } return(ToArray(list._tail, array, currentIndex + 1)); }
private static T GetItem(HeadTailList <T> list, int currentIndex, int index) { var head = list._hasHead ? list._head : throw new ArgumentOutOfRangeException(nameof(index), index, "Argument is out of range."); if (currentIndex == index) { return(head); } var tail = list._tail?._hasHead ?? false ? list._tail : throw new ArgumentOutOfRangeException(nameof(index), index, "Argument is out of range."); return(GetItem(list._tail, currentIndex + 1, index)); }
public void Deconstruct(out T head, out HeadTailList <T> tail) { head = Head; tail = Tail; }
public HeadTailListEnumerator(HeadTailList <T> list) { _original = list; _current = null; }