# Sodium
Port of [Sodium](https://github.com/SodiumFRP/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`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Stream)
and [`Cell`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.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`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Stream)
and [`Cell`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Cell) classes.
### Forward references
In situations, where a stream or cell needs to be referenced *before* it is assigned, use
[`StreamLoop`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.StreamLoop) or
[`CellLoop`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.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`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.StreamSink) and
[`CellSink`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.CellSink).
And, whenever you need to get data out of the model, use
[`Stream.listen()`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Stream.listen)
and [`Cell.listen()`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.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()`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.transaction.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](https://www.manning.com/books/functional-reactive-programming).
Even though, the book aims Java, it is pretty straightforward to map it into Python.
## Examples
See [examples](examples) directory.
## Development
To run the tests, execute `pytest` from the package directory.
To build [API reference](https://sodium-python.readthedocs.io), 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](https://github.com/SodiumFRP/sodium/blob/master/COPYING).
Raw data
{
"_id": null,
"home_page": "https://github.com/mode89/sodium-python",
"name": "sodiumfrp",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "",
"author": "Stephen Blackheath",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/1b/ae/bb91d2139a150cea6eb90e67f0068566da686a1c21219a81dc48f310ff4c/sodiumfrp-1.0.1.tar.gz",
"platform": null,
"description": "# Sodium\n\nPort of [Sodium](https://github.com/SodiumFRP/sodium) - Functional Reactive Programming (FRP) library - to Python.\n\n\n## Installation\n\nJust `pip install sodiumfrp`.\n\n\n## Main Concepts\n\n### Streams and Cells\n\nThis library is based on two types:\n[`Stream`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Stream)\nand [`Cell`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Cell).\n`Stream` represents a *stream of events*, while `Cell` represents a *value that changes over time*.\n\n### Operators\n\nThere is also a bunch of primitives that you can use to build streams/cells and to compose them together.\nThey provide means for doing common operations like mapping, filtering, reduction, flat-mapping and more.\nAll of them are implemented as members of\n[`Stream`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Stream)\nand [`Cell`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Cell) classes.\n\n### Forward references\n\nIn situations, where a stream or cell needs to be referenced *before* it is assigned, use\n[`StreamLoop`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.StreamLoop) or\n[`CellLoop`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.CellLoop).\n\n### Interfacing with imperative world\n\n`Stream` and `Cell` lets you model your business logic in a *purely functional* way.\nIn order to provide your model with input data, use\n[`StreamSink`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.StreamSink) and\n[`CellSink`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.CellSink).\nAnd, whenever you need to get data out of the model, use\n[`Stream.listen()`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Stream.listen)\nand [`Cell.listen()`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.primitives.Cell.listen).\n\nWhen an input value is pushed into a stream or cell, Sodium automatically starts a *transaction*.\nAny state changes, that occur as a result of that input, are performed within the same *transaction*.\nMost of the time you don't need to do anything, but it is possible to start a transaction explicitly via\n[`Transaction.run()`](https://sodium-python.readthedocs.io/en/latest/sodiumfrp.html#sodiumfrp.transaction.Transaction.run).\nFor example:\n* It often makes sense for all the program initialization to be wrapped in a single, big transaction.\n* `StreamLoop` and `CellLoop` require an explicit transaction.\n\n### The Book\n\nThe most comprehensive guide on FRP and this library would be the book\n[Functional Reactive Programming by Stephen Blackheath](https://www.manning.com/books/functional-reactive-programming).\nEven though, the book aims Java, it is pretty straightforward to map it into Python.\n\n\n## Examples\n\nSee [examples](examples) directory.\n\n\n## Development\n\nTo run the tests, execute `pytest` from the package directory.\n\nTo build [API reference](https://sodium-python.readthedocs.io), go to `docs` directory and run `make html`.\nIt requires `sphinx` and `sphinx-rtd-theme` packages to be installed.\n\n\n## License\n\nDistributed under [BSD 3-Clause](https://github.com/SodiumFRP/sodium/blob/master/COPYING).\n",
"bugtrack_url": null,
"license": "BSD-3 License",
"summary": "Python implementation of Sodium - Functional Reactive Programming (FRP) library",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/mode89/sodium-python"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "8136befc2caabc2f28e192beb67656177ae82dec5ae93c2ebcbd6882ab452638",
"md5": "66206ad572e3ac8ab1c368b78687ac0b",
"sha256": "29d72227f64d6bd951f9a7fc66915a2889f71b3ec288a215b6f2ab2b61b00b24"
},
"downloads": -1,
"filename": "sodiumfrp-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "66206ad572e3ac8ab1c368b78687ac0b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 27986,
"upload_time": "2023-07-17T05:54:56",
"upload_time_iso_8601": "2023-07-17T05:54:56.516605Z",
"url": "https://files.pythonhosted.org/packages/81/36/befc2caabc2f28e192beb67656177ae82dec5ae93c2ebcbd6882ab452638/sodiumfrp-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1baebb91d2139a150cea6eb90e67f0068566da686a1c21219a81dc48f310ff4c",
"md5": "5020a04ce5feb5908beebb471cee624a",
"sha256": "b7b57af95e9b9d3f42d0840dc02df565fc7c677537e40a543163b4bd938c2150"
},
"downloads": -1,
"filename": "sodiumfrp-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "5020a04ce5feb5908beebb471cee624a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 23387,
"upload_time": "2023-07-17T05:54:58",
"upload_time_iso_8601": "2023-07-17T05:54:58.692478Z",
"url": "https://files.pythonhosted.org/packages/1b/ae/bb91d2139a150cea6eb90e67f0068566da686a1c21219a81dc48f310ff4c/sodiumfrp-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-07-17 05:54:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mode89",
"github_project": "sodium-python",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "sodiumfrp"
}