Realising an Iterator
Learn why you would need to realize an iterator and how you would go about doing it.
We'll cover the following...
We'll cover the following...
It is sometimes useful to convert an iterator into a concrete sequence such as a list. This is sometimes called “realizing” the iterator.
Reasons for realizing an iterator
There are several reasons you might want to realize an iterator:
- To find its length
- To access the elements more than once (an iterator can only be read from once, afterwards it is spent)
- To access the elements in a different order
- To print it
The process of realizing an iterator involves evaluating every term in the iterator and making those terms available as a ...