Skip to main content

running effects on value updates with dependency discovery - conceptually inspired by Signal in JavaScript

Project description

Lazy Signals 🪢

lazysignals is a python library to run effects on state changes. It employs dependency discovery and is lazy. It is conceptually inspired by Signal in JavaScript.

Example

The framework runs relevant effects whenever some state changes:

define a new signal s, holding the initial value 1

s = Signal(1)

derive a signal that checks the parity of s

p = derived(lambda: s.value % 2 == 0)

log the parity of s to the console

effect(lambda: print(f"parity:", "even" if p.value else "odd"))

perform some updates to s

s.value = 1  # no change, no output
s.value = 2  # output: "parity: even"
s.value = 3  # output: "parity: odd"
s.value = 5  # no change, no output
s.value = 6  # output: "parity: even"

Have a look at example.py for more; run with pipenv install (to locally install this library) and pipenv run example.

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

lazy_signals-0.1.0.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

lazy_signals-0.1.0-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file lazy_signals-0.1.0.tar.gz.

File metadata

  • Download URL: lazy_signals-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for lazy_signals-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1cccdc9428c181cc649cd392d77634841562237210569285fe68a6e8390b38e1
MD5 8eef397136d6e56822df698129e58d6f
BLAKE2b-256 6ec2dc197cb4d3525558bd5a98bc471f557bc6e512220e926b3748ee273b9bbe

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazy_signals-0.1.0.tar.gz:

Publisher: release.yaml on adrian-gallus/lazy-signals-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lazy_signals-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: lazy_signals-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for lazy_signals-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 affed999016b0b5b7fef05e803c7a08f40b0e542d92a1561fa7fb1736040ecd7
MD5 2858d236990b7aa136c4478157632af5
BLAKE2b-256 3c2b1abbeecd3aa05eddc50cdcac73fefcf7ff1d32fee65da0d93899c66ce9b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for lazy_signals-0.1.0-py3-none-any.whl:

Publisher: release.yaml on adrian-gallus/lazy-signals-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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