Singly linked lists with incremental instantiation of iterators
Project description
Package Description
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:
>>> 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:
>>> 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'])
Chain are typically a lot less efficient than using ordinary arrays. So, almost all the time you should carry on using ordinary arrays and/or tuples. But Chains 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".
By contrast, we would immediately go to a fully expanded chain if we were to simply apply chain:
>>> from lazychains import chain
>>> c = chain( "abc" )
>>> c
chain(['a','b','c'])
>>>
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
File details
Details for the file lazychains-0.2.12.tar.gz
.
File metadata
- Download URL: lazychains-0.2.12.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-10043-tuxedo
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77c75a9dca5e03e00a660cf71aacce99acd4ec90e4d60c24286a4fab7f0d5907 |
|
MD5 | c56276b6d27510700ee626a13def43a4 |
|
BLAKE2b-256 | 9074e21b013a0ab2c2bf31ba355fca7c9fc70e8d9be4798ebe450fe13975d8cc |
File details
Details for the file lazychains-0.2.12-py3-none-any.whl
.
File metadata
- Download URL: lazychains-0.2.12-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.10.12 Linux/6.5.0-10043-tuxedo
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5964d4eaec4d7e48ce13bec5235c325f4998b90a57d1a0b6635492f568d7139 |
|
MD5 | e32477e06cdd980127f4ee12b64b9a33 |
|
BLAKE2b-256 | 25b8d450fdce3cc19c490e47c27d040725d7c0f8084524776b0c3c521cbb243f |