https://github.com/timoniq/fntypes
Functional typing in Python
https://github.com/timoniq/fntypes
Last synced: about 1 year ago
JSON representation
Functional typing in Python
- Host: GitHub
- URL: https://github.com/timoniq/fntypes
- Owner: timoniq
- Created: 2024-01-26T07:44:52.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-09T05:23:30.000Z (over 1 year ago)
- Last Synced: 2025-04-19T17:58:00.845Z (over 1 year ago)
- Language: Python
- Homepage:
- Size: 112 KB
- Stars: 11
- Watchers: 1
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# fntypes
Functional typing in Python!
See [examples](/examples/)
See [documentation](/docs/index.md)
fntypes is based on the belief that raising exceptions **should be avoided**. Therefore, it offers a set of functional types needed to write better code. This type strategy grants your project with higher control over type system - improves control flow
Contributions are welcome
```python
@unwrapping
def send_funds(
sender_id: int,
receiver_id: int,
amount: decimal.Decimal,
) -> Result[TransactionID, str]:
sender = get_user(sender_id).expect("Sender is undefined")
receiver = get_user(receiver_id).expect("Receiver is undefined")
if sender.get_balance().unwrap() < amount:
return Error("Sender has not enough funds to complete transaction")
return Ok(
create_transaction(sender, receiver, amount)
.unwrap()
.transaction_id
)
```