Design and implement a resumable iterator that can pause mid-traversal and later resume from the exact position it left off. The iterator must expose a clean interface: next() to yield the next element, get_state() to capture the current position, and set_state(state) to restore that position. You will build this abstraction for three progressively harder cases:
Part 1 – 1-D lists: Implement ResumableListIterator that works on a plain Python list. State is simply an index; get_state() returns it and set_state(idx) rewinds or fast-forwards to that index. Handle StopIteration when the list is exhausted.
Part 2 – Single large JSON file: Implement ResumableFileIterator that streams a single JSON file containing one JSON object per line (newline-delimited JSON). The file may be larger than memory, so you must not load it fully. State must capture both the byte offset in the file and the line number so that set_state can seek to that offset and resume parsing from the next newline. Survive empty lines and valid JSON objects spread across multiple lines.
Part 3 – Multiple JSON files: Implement ResumableMultiFileIterator that chains many such files together. State must encode (file_index, byte_offset, line_number) so that iteration can resume in the middle of any file, correctly skipping empty files and surviving file additions or deletions between pause and resume (you may assume the file list is immutable once the iterator is created). Provide full unit tests that iterate a few steps, snapshot state, continue, then restore every saved state and assert the remaining elements match the original continuation.