Uma biblioteca inspirada em Rust e Kotlin para lidar com Option, println colorido e utilitários.
Project description
🦀 Koruspy 0.5.0 – The Async Update
Koruspy é uma biblioteca ultra-leve que traz a segurança do Rust e a elegância do Kotlin para o Python. Desenvolvida totalmente via Termux, ela elimina a necessidade de verificações manuais de None e blocos repetitivos try/except usando programação funcional e Pattern Matching.
🆕 Novidades da Versão 0.5.0
- Módulo Assíncrono (
AsyncOption): Suporte completo paraasync/await. Pipelines que aceitam funções síncronas e assíncronas misturadas. option_ofInteligente: Agora aceita um valor padrão (fallback) caso o valor principal seja nulo ounothing.- Robustez nos Testes: 34 testes automatizados cobrindo 100% dos novos fluxos.
- Identidade Única: Singleton
nothinggarantido em toda a aplicação.
🚀 Diferenciais
- Zero NoneErrors: Use
Option(Someounothing) para lidar com valores ausentes. - Result Pattern: Trate sucessos (
Okay) e falhas (Err) como dados. - Estilo Kotlin: Métodos encadeáveis como
.map(),.filter(),.and_then(). - Terminal Colorido: Substitua
printporprintlnpara saídas com cores ANSI automáticas.
⚡ Programação Assíncrona (Async)
A Koruspy integra pipelines funcionais com asyncio de forma transparente.
Métodos Assíncronos Principais
| Método | Descrição |
|---|---|
map_async(fn) |
Transforma o valor (aceita async def ou lambda). |
filter_async(cond) |
Filtra o valor (aceita async def ou lambda). |
unwrap_or_async(val) |
Retorna o valor ou fallback (valor ou função async). |
if_present_async(fn) |
Executa tarefa se houver valor (aguarda se for async). |
on_nothing_async(fn) |
Executa tarefa se for nothing (aguarda se for async). |
Exemplo de Uso Async
import asyncio
from koruspy import async_option, Some, nothing
async def buscar_usuario(id):
await asyncio.sleep(0.1)
return Some({"nome": "Koruspy", "admin": True}) if id == 1 else nothing
async def main():
nome = await (
async_option(buscar_usuario(1))
.filter_async(lambda u: u["admin"])
.map_async(lambda u: u["nome"].upper())
.unwrap_or_async("CONVIDADO")
)
print(nome) # Saída: KORUSPY
asyncio.run(main())
📝 Exemplos Síncronos
option_of com Fallback
from koruspy import option_of, println
# Se for None, assume o padrão 18
idade = option_of(None, 18)
println(idade) # Some(18)
# Preserva valores falsy (como 0 ou False)
saldo = option_of(0, 100)
println(saldo) # Some(0)
Pipeline com Filtros e Loops
from koruspy import option_of, println
arquivos = ["config.yaml", "", None, "dados.json"]
for nome in arquivos:
resultado = (
option_of(nome, "")
.filter(lambda x: x.endswith((".yaml", ".json")))
.map(lambda x: x.upper())
.unwrap_or("IGNORADO")
)
println(resultado)
✅ Qualidade e Testes Passando em 34 testes automatizados:
- Mônadas Some, nothing, Okay, Err.
- AsyncOption com suporte a corrotinas.
- Integração com Generators e loops.
- Conversões seguras com to_float. 📦 Instalação pip install koruspy
🇺🇸 English Summary Koruspy brings Option and Result types to Python. Version 0.5.0 introduces AsyncOption, allowing seamless async/await pipelines.
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.5.0.tar.gz.
File metadata
- Download URL: koruspy-0.5.0.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4be494c1369f0f48b684b76aa23fa86059cbcf766ed8ba0b90bc5d38ad420a0d
|
|
| MD5 |
7e1aa83b0fbe80d97aa84e504813d0ca
|
|
| BLAKE2b-256 |
269105a158f30ec4d659cb94506485006945388e77b011eb6c02c684a59948b2
|
File details
Details for the file koruspy-0.5.0-py3-none-any.whl.
File metadata
- Download URL: koruspy-0.5.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6c21cd780fa39072bb62a770f01f01234cc587b14df3ba53dc5da6f2ea1f9d2
|
|
| MD5 |
bd5c5640e3284fac5f8855c526741c09
|
|
| BLAKE2b-256 |
6bcb3a59823928df8fcdc982ecfcf5c42ba3cc6aa4e0bd2ff8c969160a184490
|