You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+35-24Lines changed: 35 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,21 +5,51 @@
5
5
</p>
6
6
7
7
8
-
ResultContainer is a python module with a `Result` class that mimics the [Result Result Enum](https://doc.rust-lang.org/std/result/enum.Result.html). The Result Enum is used for situations when errors are expected and are easily handled, or you do not want to have lots of try/except clauses. The Result enum wraps a value in an `Ok` variant, until there is an exception or error raised, and then it is converted to the `Err` variant. The `Err` variant is a `ResultErr` object stored in the `Result` that contains the error messages and traceback information. The `Result` object includes similar methods to the Result Result Enum for inquiry about the state, mapping functions, and passing attributes/methods to the containing `value`.
8
+
The `ResultContainer` module simplifies complex error handling into clean, readable, and maintainable code structures. Error handling in Python can often become unwieldy, with deeply nested `try/except` blocks and scattered error management. The `ResultContainer` is used for situations when errors are expected and are easily handled. Inspired by [Rust’s Result<Ok, Err>](https://doc.rust-lang.org/std/result/enum.Result.html) enum, `ResultContainer` introduces a clean and Pythonic way to encapsulate success (`Ok`) and failure (`Err`) outcomes.
9
9
10
-
#### `Result` Variants
10
+
The `ResultContainer.Result` enum wraps a value in an `Ok` variant, until there is an exception or error raised, and then it is converted to the `Err` variant. The `Err` variant wraps a `ResultContainer.ResultErr` object that contains the error messages and traceback information. The `Result` object includes similar methods to the Rust Result Enum for inquiry about the state, mapping functions, and passing attributes/methods to the containing `value`.
11
+
12
+
The `ResultContainer` is designed to streamline error propagation and improve code readability, `ResultContainer` is ideal for developers seeking a robust, maintainable approach to handling errors in data pipelines, API integrations, or asynchronous operations.
13
+
14
+
## Features
15
+
16
+
-**Variants for Success and Failure**: Two variants represented in a Result instance, `Ok(value)` for successful outcomes, and `Err(e)` for errors that have resulted. Provides a flexible mechanism for chaining operations on the `Ok` value while propagating errors through `Err`.
17
+
-**Attribute and Method Transparency**: Automatically passes attributes, methods, indices, and math operations to the value contained within an `Ok`, otherwise propagates the `Err(e)`.
18
+
-**Utility Methods**: Implements helper methods for error propagation, transformation, and querying (e.g., `.map()`, `.apply()`, `.unwrap_or()`, `.expect()`, `.raises()`) for concise and readable handling of success and error cases.
then rename the file `ResultContainer/__init__.py` to `ResultContainer/ResultContainer.py` and move `ResultContainer.py` to wherever you want to use it.
32
+
33
+
## `Result` Variants
34
+
35
+
```python
36
+
# Result is the main class and Ok and Err are constructors.
37
+
from ResultContainer import Result, Ok, Err
38
+
```
11
39
12
40
-`Ok(value)`
13
41
-`value` is wrapped within an `Ok`.
14
42
- Constructor: `Result.as_Ok(value)`
43
+
-`Result.Ok` attribute returns the wrapped `value`
15
44
-`Err(e)`
16
45
-`e` is a `ResultErr` object wrapped within an `Err`.
17
46
- Constructor: `Result.as_Err(error_msg)`
47
+
-`Result.Err` attribute returns the wrapped `e`.
18
48
19
49
20
-
####Properties of the `Result` Variants
50
+
### Properties of the `Result` Variants
21
51
22
-
#####`Ok(value)`
52
+
#### `Ok(value)`
23
53
24
54
- Represents success (non-error state).
25
55
The `value` is wrapped within the `Ok()`.
@@ -42,7 +72,7 @@ ResultContainer is a python module with a `Result` class that mimics the [Result
42
72
-`Err(e1) < Err(e2) ` ➣ `False`
43
73
-`Err(e1) <= Err(e2) ` ➣ `True`
44
74
45
-
#####`Err(e)`:
75
+
#### `Err(e)`:
46
76
47
77
- Represents a failure (error-state) and contains `e` as a `ResultErr` object
48
78
that stores error messages and traceback information.
@@ -54,25 +84,6 @@ ResultContainer is a python module with a `Result` class that mimics the [Result
54
84
55
85
There are methods built into `Result` to check if an error has been raised, or the unwrap the value/error to get its contents.
56
86
57
-
## Features
58
-
59
-
-**Variants for Success and Failure**: Two variants, `Ok(value)` for successful outcomes, and `Err(e)` for errors that have resulted. Provides a flexible mechanism for chaining operations on the `Ok` value while propagating errors through `Err`.
60
-
-**Attribute and Method Transparency**: Automatically passes attributes, methods, and math operations to the value contained within an `Ok`, otherwise propagates the `Err(e)`.
61
-
-**Utility Methods**: Implements helper methods for error propagation, transformation, and querying (e.g., `.map()`, `.apply()`, `.unwrap_or()`, `.expect()`, `.raises()`) for concise and readable handling of success and error cases.
then rename the file `ResultContainer/__init__.py` to `ResultContainer/ResultContainer.py` and move `ResultContainer.py` to wherever you want to use it.
0 commit comments