Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nickderobertis/pyrop
Imperative-style railway-oriented programming in Python
https://github.com/nickderobertis/pyrop
Last synced: 1 day ago
JSON representation
Imperative-style railway-oriented programming in Python
- Host: GitHub
- URL: https://github.com/nickderobertis/pyrop
- Owner: nickderobertis
- License: mit
- Created: 2023-08-22T10:12:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-08-22T23:20:13.000Z (over 1 year ago)
- Last Synced: 2024-12-25T23:18:04.903Z (about 1 month ago)
- Language: Python
- Size: 1.11 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
[![](https://codecov.io/gh/nickderobertis/pyrop/branch/main/graph/badge.svg)](https://codecov.io/gh/nickderobertis/pyrop)
[![PyPI](https://img.shields.io/pypi/v/pyrop)](https://pypi.org/project/pyrop/)
![PyPI - License](https://img.shields.io/pypi/l/pyrop)
[![Documentation](https://img.shields.io/badge/documentation-pass-green)](https://nickderobertis.github.io/pyrop/)
![Tests Run on Ubuntu Python Versions](https://img.shields.io/badge/Tests%20Ubuntu%2FPython-3.9%20%7C%203.10-blue)
![Tests Run on Macos Python Versions](https://img.shields.io/badge/Tests%20Macos%2FPython-3.9%20%7C%203.10-blue)
![Tests Run on Windows Python Versions](https://img.shields.io/badge/Tests%20Windows%2FPython-3.9%20%7C%203.10-blue)
[![Github Repo](https://img.shields.io/badge/repo-github-informational)](https://github.com/nickderobertis/pyrop/)# pyrop
## Overview
Imperative-style railway-oriented programming in Python,
including fully-typed errors. Supports sync and async
functions and methods.## Getting Started
Install `pyrop`:
```
pip install pyrop
```A simple example:
```python
from pyrop import EitherMonad, Left, catch, monadiccatcher = catch[ValueError | TypeError]()
@catcher
def func_with_error() -> None:
raise ValueError("This is an error")@catcher
def success_func() -> int:
return 1@monadic
def func(do: EitherMonad[ValueError | TypeError]) -> int:
value = do << success_func()
print(f"Value is {value}")
do << func_with_error()
print("This will not execute")
return valueres = func()
assert isinstance(res, Left)
assert isinstance(res.value, ValueError)try:
func().get()
except ValueError as e:
print(f"Caught error: {e}")assert func().map_left(lambda e: "Error occurred") == Left("Error occurred")
assert func().get_or_else(1) == 1
```## Links
See the
[documentation here.](
https://nickderobertis.github.io/pyrop/
)## Development Status
This project is currently in early-stage development. There may be
breaking changes often. While the major version is 0, minor version
upgrades will often have breaking changes.## Developing
See the [development guide](
https://github.com/nickderobertis/pyrop/blob/main/DEVELOPING.md
) for development details.## Author
Created by Nick DeRobertis. MIT License.