Skip to main content

Uma biblioteca inspirada em Rust e Kotlin para lidar com Option, println colorido e utilitários.

Project description

[koruspy version 0.2.8 ChangeLog]:

- `get_value()` was remastered. Previously overshadowed by `finalize()`, it now returns a new `Option` (`Some` or `nothing`) instead of a raw value.

[koruspy versão 0.2.8 quadro de mudanças]:

- a função `get_value()` foi remasterizada. anteriormente sobreposta pela função `finalize()`, agora retornando um novo objeto `Option` (`Some` ou `nothing`), ao invés de um valor cru.

🦀 Koruspy

Koruspy é uma biblioteca ultra-leve que traz a segurança do Rust e a elegância do Kotlin para o ecossistema Python.

Desenvolvida inteiramente via Termux, esta biblioteca elimina a necessidade de verificações manuais de None e blocos try/except repetitivos, utilizando o poder do Pattern Matching (Python 3.10+) e programação funcional.


🚀 Diferenciais

Zero NoneErrors: Use Option (Some ou nothing) para lidar com valores ausentes.

Result Pattern: Trate sucessos e falhas como dados, não como exceções que quebram o código.

Estilo Kotlin: Métodos encadeáveis como .map(), .Filter(), .and_then() e o operador de navegação segura .getattr().

Pipeline seguro: option_of agora trata corretamente None e nothing, preservando valores falsy como 0 e False.

Finalização clara: .finalize() encerra pipelines que já têm valor garantido.

Fallback elegante: .unwrap_or(default) e .unwrap_or_else(func) fornecem valores quando necessário.

Terminal Colorido: Substitua o print padrão pelo println com suporte a tipos e cores ANSI.


📦 Instalação

Como você está desenvolvendo no Termux ou em ambiente mobile, instale via modo editável:

pip install -e .


📝 Exemplos 2.8

option_of trata None e nothing, preservando falsy

from koruspy import Some, nothing, option_of, println


idade = option_of(0, 18)
println(idade)  # Some(0)

idade2 = option_of(None, 18)
println(idade2)  # Some(18)

Pipeline com Filter e finalize

idade_valida = (
    option_of(idade2.get_value(), 0)
    .Filter(lambda x: x >= 18)
    .on_nothing(lambda: println("valor inválido"))
    .finalize()
)
println(idade_valida)

Fallbacks

val = option_of(None).unwrap_or(42)
println(val)  # 42

val2 = option_of(None).unwrap_or_else(lambda: 99)
println(val2)  # 99

função get_value():

from koruspy import option_of

arquivos = ["config.yaml", "", None, "dados.json"]

for nome in arquivos:
    opt = option_of(nome)

    resultado = (
        opt
        .get_value()                      # 👈 retorna Option
        .filter(lambda x: x.endswith((".yaml", ".json")))
        .map(lambda x: x.upper())
    )

    print(resultado)

English Version 🇺🇸🇬🇧:

🦀 Koruspy

Koruspy is an ultra-lightweight library that brings Rust’s safety and Kotlin’s elegance to the Python ecosystem.

Developed entirely via Termux, this library removes the need for manual None checks and repetitive try/except blocks by leveraging the power of Pattern Matching (Python 3.10+) and functional programming.


🚀 Highlights

Zero NoneErrors: Use Option (Some or nothing) to safely handle missing values.

Result Pattern: Handle success and failure as data, not as exceptions that break control flow.

Kotlin-style API: Chainable methods like .map(), .Filter(), .and_then(), and the safe navigation operator .getattr().

Safe pipeline: option_of now correctly handles None and nothing, while preserving falsy values such as 0 and False.

Clear finalization: .finalize() terminates pipelines when a value is guaranteed.

Elegant fallbacks: .unwrap_or(default) and .unwrap_or_else(func) provide values when needed.

Colored terminal output: Replace the standard print with println, with type-aware ANSI color support.


📦 Installation

If you are developing on Termux or in a mobile environment, install using editable mode:

pip install -e .


📝 Examples 2.8

option_of handles None and nothing, preserving falsy values

from koruspy import Some, nothing, option_of, println


age = option_of(0, 18)
println(age)  # Some(0)

age2 = option_of(None, 18)
println(age2)  # Some(18)

Pipeline with Filter and finalize

valid_age = (
    option_of(age2.get_value(), 0)
    .Filter(lambda x: x >= 18)
    .on_nothing(lambda: println("invalid value"))
    .finalize()
)
println(valid_age)

Fallbacks

val = option_of(None).unwrap_or(42)
println(val)  # 42

val2 = option_of(None).unwrap_or_else(lambda: 99)
println(val2)  # 99

function get_value():

from koruspy import option_of

user_inputs = ["42", "", None, "abc"]

for value in user_inputs:
    result = (
        option_of(value)
        .get_value()                 # 👈 returns a new Option
        .map(int)
        .filter(lambda x: x > 0)
    )

    print(result)

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.2.8.tar.gz (4.2 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.2.8-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for koruspy-0.2.8.tar.gz
Algorithm Hash digest
SHA256 98389429e4ae8e2575c83ac369c56a8d3bde5c51901d171c5a07d7c64b804e90
MD5 842489df6846a73a1078b2ddee31cbd1
BLAKE2b-256 d14ca7d39b19a4d46ff70f72c0dc8431a40493699b503169cbf616e8673c2ea7

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for koruspy-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 10ccad0e78c9836d68cf38e2140c511a1a538cb8e3cf544ec8aa26ba577250c9
MD5 d19c845f963f24f45bba3cde8aab29da
BLAKE2b-256 39458eee6489081341a72f63d5e63447ee778a82f571aa9d8fef1e33803b580d

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