Skip to content
This repository has been archived by the owner on Jul 7, 2024. It is now read-only.
/ ruption Public archive

Reliability utilities with good type hinting based on Rust's Option/Result

License

Notifications You must be signed in to change notification settings

phantie/ruption

Repository files navigation

  • Implements pacify module
  • Implements subset of Option enum
  • Implements subset of Result enum

Examples:

Option:

from ruption.option import some
assert (
    some(2)
    .map(lambda x: x * 2)
    .inspect(print) # output: 4
    .unwrap()) == 4

Result:

from ruption.result import ok
assert (
    ok(2)
    .map(lambda x: x * 2)
    .inspect(print) # output: 4
    .unwrap()) == 4

Pacify:

from ruption.pacify import pacify_callable_result
from ruption.pacify import pacify_call_result
from ruption.pacify import pacify_callable
from ruption.pacify import pacify_call

# pacify_callable for Option, pacify_callable_result for Result
@pacify_callable_result()
def div(dividend, divisor):
    return dividend / divisor

assert div(10, 5).is_ok_and(lambda r: r == 2)
assert div(10, 0).is_err_and(lambda e: isinstance(e, ZeroDivisionError))

# pacify_call for Option, pacify_call_result for Result
assert pacify_call(lambda: 2 + 2).contains(4)

Imports:

from ruption.pacify import *
from ruption.option import Option, some, none
from ruption.result import Result, ok, err
from ruption.panic import Panic

Installation:

pip install git+https://github.com/phantie/ruption.git

Releases

No releases published

Languages