Singly linked lists with incremental instantiation of iterators
Project description
lazychains
A Python library to provide "chains", which are Lisp-like singly linked lists that support the lazy expansion of iterators. For example, we can construct a Chain of three characters from the iterable "abc" and it initially starts as unexpanded, shown by the three dots:
.. code:: python
from lazychains import lazychain c = lazychain( "abc") c chain([...])
We can force the expansion of c by performing (say) a lookup or by forcing the whole chain of items by calling expand:
.. code:: python
c[1] # Force the expansion of the next 2 elements. True c chain(['a','b',...]) c.expand() # Force the expansion of the whole chain. chain(['a','b','c'])
As we will see, chains are generally less efficient than ordinary arrays. So, as a default you should definitely carry on using ordinary arrays and tuples most of the time. But they have a couple of special features that makes them the perfect choice for some problems.
- Chains are immutable and hence can safely share their trailing segments.
- Chains can make it easy to work with extremely large (or infinite) sequences.
Expanded or Unexpanded
When you construct a chain from an iterator, you can choose whether or not it should be immediately expanded by calling chain rather than lazychain. The difference between the two is pictured below. First we can see what happens in the example given above where we create the chain using lazychain on "abc".
IMAGE GOES HERE
By contrast, we would immediately go to a fully expanded chain if we were to simply apply chain:
.. code:: python
from lazychains import chain c = chain( "abc" ) c chain(['a','b','c'])
IMAGE GOES HERE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for lazychains-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a97db6e8cab9c4fca715a862fe6be736258feff2320f1d4b4d43cae76e7368cd |
|
MD5 | 1073049a31c258aeded20516210c9837 |
|
BLAKE2b-256 | 11bc058957db01c2b9e3ea3393f287b3750134a0f063c587de8e60ab911845a0 |