diff --git a/README.md b/README.md index 04314a3..a2b1d62 100644 --- a/README.md +++ b/README.md @@ -101,12 +101,18 @@ For those running Python 3.10, you can make use of Python's **structural pattern ``` >>> from resultify import Ok, Err ->>> ok = Ok('ok!') +>>> ok = Ok("ok!") >>> match ok: -... case Ok(_value=foo): print(f"Yay {foo}") -... case Err(_value=foo): print(f"Nay {foo}") +... case Ok(foo): print(f"Yay {foo}") +... case Err(foo): print(f"Nay {foo}") ... Yay ok! +>>> no = Err("nope!") +>>> match no: +... case Ok(foo): print(f"Yay {foo}") +... case Err(foo): print(f"Nay {foo}") +... +Nay nope! ``` diff --git a/resultify/__init__.py b/resultify/__init__.py index 53a04c9..af53ea1 100644 --- a/resultify/__init__.py +++ b/resultify/__init__.py @@ -11,6 +11,8 @@ class Ok(Generic[T]): A value that indicates success and which stores arbitrary data for the return value. """ + __match_args__ = ("_value",) + def __init__(self, value: T = True) -> None: self._value = value @@ -50,6 +52,8 @@ class Err(Generic[E]): A value that signifies failure and which stores arbitrary data for the error. """ + __match_args__ = ("_value",) + def __init__(self, value: E = True) -> None: self._value = value