Skip to main content

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 para async/await. Pipelines que aceitam funções síncronas e assíncronas misturadas.
  • option_of Inteligente: Agora aceita um valor padrão (fallback) caso o valor principal seja nulo ou nothing.
  • Robustez nos Testes: 34 testes automatizados cobrindo 100% dos novos fluxos.
  • Identidade Única: Singleton nothing garantido em toda a aplicação.

🚀 Diferenciais

  • Zero NoneErrors: Use Option (Some ou nothing) 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 print por println para 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

koruspy-0.6.0.tar.gz (113.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

koruspy-0.6.0-py3-none-any.whl (115.6 kB view details)

Uploaded Python 3

File details

Details for the file koruspy-0.6.0.tar.gz.

File metadata

  • Download URL: koruspy-0.6.0.tar.gz
  • Upload date:
  • Size: 113.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for koruspy-0.6.0.tar.gz
Algorithm Hash digest
SHA256 3b37c618825c746fff8946608946d919cbc06561c407858959f5a3a4cfc636b5
MD5 90399f8d5353f30fe759a9a10f389466
BLAKE2b-256 2ed4c1c3af64886ba5bcc42ffdc7419bab0178e1bf3b76c828b6d0343630ba23

See more details on using hashes here.

File details

Details for the file koruspy-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: koruspy-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 115.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.5

File hashes

Hashes for koruspy-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1edd057b87d9c63aec78c3c17cff7c6bedd5ad4181a996c5185b5cbf51b45a3e
MD5 0734039d910900ea1abb759cfa1d5bf3
BLAKE2b-256 a2bb5779585c415777147af387627eb18bcd62a672ec4ca6fbd4f241a37a2f2f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page