Skip to main content

Singly linked lists with incremental instantiation of iterators

Project description

Package Description

CI Documentation Status

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".

chain

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'])
>>> 

lazychain

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lazychains-0.3.0.tar.gz (81.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lazychains-0.3.0-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file lazychains-0.3.0.tar.gz.

File metadata

  • Download URL: lazychains-0.3.0.tar.gz
  • Upload date:
  • Size: 81.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lazychains-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9636f868267cc85d85bc07324c1208b849e693c51759b416747390d6ec792bd4
MD5 441e109685f4ed8088840235b2ec4392
BLAKE2b-256 39402df266116fd7ab1d6f5457a2a577cb0e112bc4f4542fc53e16dcd3dfd542

See more details on using hashes here.

File details

Details for the file lazychains-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: lazychains-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for lazychains-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4f9fcb9e33bbb6ec5fe401bf90857ca4b0b4984c1a0b0ff315f2e077ed71aa33
MD5 cd28c3e00e91f96a8c79678d6c081670
BLAKE2b-256 14552d2d98cab3fc81b663491848172c1e64fcf28afba8d2c0bd5a2163ad7021

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page