Navigation

A lazy list is an iterator that behaves like a list and possesses a cache
mechanism. A lazy list is potentially infinite and speed performances of the
cache is comparable with Python lists. One major difference with original
Python list is that lazy list are immutable. The advantage is that slices
share memory.

You can easily create your own class inheriting from lazy_list_generic. You
should call the lazy_list_generic constructor (optionally with some
precomputed values for the cache) and implement the method _new_slice that
returns a new chunk of data at each call. Here is an example of implementation
of the Thue–Morse word that is obtained as the fixed point of the substitution
\(0 \to 01\) and \(1 \to 10\):

function – a function that updates a list of precomputed values.
The update function should take as input a list and make it longer
(using either the methods append or extend). If after a call
to the update function the list of values is shorter a
RuntimeError will occurr. If no value is added then the lazy list
is considered finite.

cache – an optional list to be used as the cache. Be careful that
there is no copy.

stop – an optional integer to specify the length of this lazy list
(otherwise it is considered infinite)