Skip to main content

Python implementation of Sodium - Functional Reactive Programming (FRP) library

Project description

Sodium

Port of Sodium - Functional Reactive Programming (FRP) library - to Python.

Installation

Just pip install sodiumfrp.

Main Concepts

Streams and Cells

This library is based on two types: Stream and Cell. Stream represents a stream of events, while Cell represents a value that changes over time.

Operators

There is also a bunch of primitives that you can use to build streams/cells and to compose them together. They provide means for doing common operations like mapping, filtering, reduction, flat-mapping and more. All of them are implemented as members of Stream and Cell classes.

Forward references

In situations, where a stream or cell needs to be referenced before it is assigned, use StreamLoop or CellLoop.

Interfacing with imperative world

Stream and Cell lets you model your business logic in a purely functional way. In order to provide your model with input data, use StreamSink and CellSink. And, whenever you need to get data out of the model, use Stream.listen() and Cell.listen().

When an input value is pushed into a stream or cell, Sodium automatically starts a transaction. Any state changes, that occur as a result of that input, are performed within the same transaction. Most of the time you don't need to do anything, but it is possible to start a transaction explicitly via Transaction.run(). For example:

  • It often makes sense for all the program initialization to be wrapped in a single, big transaction.
  • StreamLoop and CellLoop require an explicit transaction.

The Book

The most comprehensive guide on FRP and this library would be the book Functional Reactive Programming by Stephen Blackheath. Even though, the book aims Java, it is pretty straightforward to map it into Python.

Examples

See examples directory.

Development

To run the tests, execute pytest from the package directory.

To build API reference, go to docs directory and run make html. It requires sphinx and sphinx-rtd-theme packages to be installed.

License

Distributed under BSD 3-Clause.

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

sodiumfrp-1.0.1.tar.gz (23.4 kB view details)

Uploaded Source

Built Distribution

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

sodiumfrp-1.0.1-py3-none-any.whl (28.0 kB view details)

Uploaded Python 3

File details

Details for the file sodiumfrp-1.0.1.tar.gz.

File metadata

  • Download URL: sodiumfrp-1.0.1.tar.gz
  • Upload date:
  • Size: 23.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for sodiumfrp-1.0.1.tar.gz
Algorithm Hash digest
SHA256 b7b57af95e9b9d3f42d0840dc02df565fc7c677537e40a543163b4bd938c2150
MD5 5020a04ce5feb5908beebb471cee624a
BLAKE2b-256 1baebb91d2139a150cea6eb90e67f0068566da686a1c21219a81dc48f310ff4c

See more details on using hashes here.

File details

Details for the file sodiumfrp-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: sodiumfrp-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 28.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for sodiumfrp-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 29d72227f64d6bd951f9a7fc66915a2889f71b3ec288a215b6f2ab2b61b00b24
MD5 66206ad572e3ac8ab1c368b78687ac0b
BLAKE2b-256 8136befc2caabc2f28e192beb67656177ae82dec5ae93c2ebcbd6882ab452638

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