Uma biblioteca inspirada em Rust e Kotlin para lidar com Option, println colorido e utilitários.
Project description
Koruspy 🦀
v0.9.5 — Biblioteca Python inspirada em abstrações funcionais (Rust / FP)
Koruspy oferece tipos como Option, Result e estruturas auxiliares com contratos claros, comportamento previsível e sem magia. A versão 0.9.5 consolida a API e introduz estruturas imutáveis e assíncronas mais robustas, preparando o caminho para a versão 1.0.0.
✨ Principais recursos
🔹 Option
Representa um valor opcional que pode estar presente (Some) ou ausente (nothing).
- Construtores:
Some(value)enothing - Operações funcionais:
map,and_then,filter,flatten - Métodos seguros de extração:
unwrap_or,unwrap_or_else,expect - Comparações bem-definidas (
__eq__) sem recursão infinita - Propagação correta de
nothing
🔹 Result
Representa o resultado de uma operação que pode ter sucesso (Okay) ou falhar (Err).
- Construtores:
Okay(value)eErr(error) - Operações funcionais:
map,and_then,flat_map,fold - Extração segura:
unwrap,unwrap_or,unwrap_or_else,unwrap_err - Exceções propagadas de forma explícita
result_of(fn)para captura automática de exceções
🔹 AsyncOption
Wrapper assíncrono para Option, compatível com await.
- Métodos assíncronos:
map_asyncand_then_asyncfilter_asyncunwrap_or_asyncunwrap_or_else_async
- Sem "auto-await" implícito ou comportamento oculto
🔹 SomeList / FrozenSomeList
Coleções funcionais baseadas em Option.
SomeList: coleção funcional mutávelFrozenSomeList:- Estrutura imutável
- Hashável (pode ser usada como chave de
dictou emset) - Baseada em
collections.abc.Sequence
- Contratos claros entre mutabilidade e imutabilidade
🧪 Qualidade e testes
- ✅ 62 testes automatizados passando
- Cobertura de testes:
- Contratos de igualdade (
__eq__) - Imutabilidade e hashing
- Propagação de
nothing/Err - Comportamento funcional consistente
- Contratos de igualdade (
- API pensada para refatoração segura
🎯 Objetivo da biblioteca
Koruspy busca ser:
- Pequena, previsível e explícita
- Livre de exceções silenciosas
- Livre de efeitos colaterais escondidos
- Priorizar clareza e correção sobre "açúcar sintático"
🚧 Status
- Versão atual: 0.9.5 (pré-1.0)
- API majoritariamente estável
- Pequenos ajustes de naming e contratos ainda podem ocorrer
- A versão 1.0.0 marcará o congelamento da API pública
📦 Instalação
pip install koruspy
🚀 Exemplo de uso
from koruspy import Some, nothing, Okay, Err, result_of
# Option
opt = Some(42)
result = opt.map(lambda x: x * 2).unwrap_or(0) # 84
# Result
def divide(a: int, b: int):
if b == 0:
return Err("Division by zero")
return Okay(a / b)
result = divide(10, 2).map(lambda x: x + 1).unwrap() # 6.0
# Captura automática de exceções
def may_fail():
return result_of(lambda: 1 / 0)
result = may_fail() # Err(ZeroDivisionError)
📄 Licença
MIT License
📞 Contato
English 🇬🇧🇺🇸
Koruspy 🦀
v0.9.5 — Python library inspired by functional abstractions (Rust / FP)
Koruspy provides types like Option, Result, and auxiliary structures with clear contracts, predictable behavior, and no magic. Version 0.9.5 consolidates the API and introduces more robust immutable and asynchronous structures, paving the way for version 1.0.0.
✨ Key Features
🔹 Option
Represents an optional value that can be present (Some) or absent (nothing).
- Constructors:
Some(value)andnothing - Functional operations:
map,and_then,filter,flatten - Safe extraction methods:
unwrap_or,unwrap_or_else,expect - Well-defined comparisons (
__eq__) without infinite recursion - Correct propagation of
nothing
🔹 Result
Represents the result of an operation that can succeed (Okay) or fail (Err).
- Constructors:
Okay(value)andErr(error) - Functional operations:
map,and_then,flat_map,fold - Safe extraction:
unwrap,unwrap_or,unwrap_or_else,unwrap_err - Explicitly propagated exceptions
result_of(fn)for automatic exception capture
🔹 AsyncOption
Asynchronous wrapper for Option, compatible with await.
- Asynchronous methods:
map_asyncand_then_asyncfilter_asyncunwrap_or_asyncunwrap_or_else_async
- No implicit "auto-await" or hidden behavior
🔹 SomeList / FrozenSomeList
Functional collections based on Option.
SomeList: mutable functional collectionFrozenSomeList:- Immutable structure
- Hashable (can be used as
dictkey or inset) - Based on
collections.abc.Sequence
- Clear contracts between mutability and immutability
🧪 Quality and Testing
- ✅ 62 automated tests passing
- Test coverage:
- Equality contracts (
__eq__) - Immutability and hashing
- Propagation of
nothing/Err - Consistent functional behavior
- Equality contracts (
- API designed for safe refactoring
🎯 Library Goals
Koruspy aims to be:
- Small, predictable, and explicit
- Free from silent exceptions
- Free from hidden side effects
- Prioritize clarity and correctness over "syntactic sugar"
🚧 Status
- Current version: 0.9.5 (pre-1.0)
- API mostly stable
- Minor naming and contract adjustments may still occur
- Version 1.0.0 will mark the freeze of the public API
📦 Installation
pip install koruspy
🚀 Usage Example
from koruspy import Some, nothing, Okay, Err, result_of
# Option
opt = Some(42)
result = opt.map(lambda x: x * 2).unwrap_or(0) # 84
# Result
def divide(a: int, b: int):
if b == 0:
return Err("Division by zero")
return Okay(a / b)
result = divide(10, 2).map(lambda x: x + 1).unwrap() # 6.0
# Automatic exception capture
def may_fail():
return result_of(lambda: 1 / 0)
result = may_fail() # Err(ZeroDivisionError)
📄 License
MIT License
📞 Contact
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file koruspy-0.9.5.tar.gz.
File metadata
- Download URL: koruspy-0.9.5.tar.gz
- Upload date:
- Size: 178.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71c9cf5ece676736037d374d0150c9654ef23d33d194c2b341e8240d2e15f2c8
|
|
| MD5 |
f424160e08915c5bb6d8861216d0b186
|
|
| BLAKE2b-256 |
4099c646ab6c8a5dead451db8c56605c816aef0cdb76c38e43bfc6b49019b2ae
|
File details
Details for the file koruspy-0.9.5-py3-none-any.whl.
File metadata
- Download URL: koruspy-0.9.5-py3-none-any.whl
- Upload date:
- Size: 172.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
378f5f3e550f4b19e083cd0bce5d585a64b637e9132a0d9350779817bfdfe744
|
|
| MD5 |
59c8438d7875a6751b743b536fd470da
|
|
| BLAKE2b-256 |
6bca6cb7c74e1d4f13245501c76d961d83f47813cf36e0046fb1266b560ae0df
|