Ok¶
Ok variant of the Result type — represents a successful computation.
Wrap a value with Ok(value) and chain operations without fear of
:class:Err short-circuits leaking into your logic. This is the right
side of the Either monad (the Right in Haskell / Scala).
ok
¶
Ok variant of the Result type — represents a successful computation.
Wrap a value with Ok(value) and chain operations without fear of
:class:Err short-circuits leaking into your logic. This is the right
side of the Either monad (the Right in Haskell / Scala).
Ok
¶
Bases: Result[ValueType, ErrorType]
Represents a successful result, holding a value of type ValueType.
Source code in src/forging_blocks/foundation/result/ok.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
is_ok: bool
property
¶
Always True — this variant holds a success value.
is_err: bool
property
¶
Always False — this variant does not hold an error.
value: ValueType
property
¶
The wrapped success value.
error: ErrorType
property
¶
Raises :class:ResultAccessError — there is no error to access.
__init__(value: ValueType) -> None
¶
__repr__() -> str
¶
__str__() -> str
¶
__eq__(other: object) -> bool
¶
Two Oks are equal when their wrapped values are equal.
__hash__() -> int
¶
map(fn: Callable[[ValueType], MappedValueType]) -> Result[MappedValueType, ErrorType]
¶
Apply fn to the wrapped value and wrap the result in a new Ok.
This is the Functor map — fmap in Haskell, .map on Scala's
Option / Either.
Source code in src/forging_blocks/foundation/result/ok.py
map_error(fn: Callable[[ErrorType], MappedErrorType]) -> Result[ValueType, MappedErrorType]
¶
Pass through unchanged — there is no error to transform.
flat_map(fn: Callable[[ValueType], Result[MappedValueType, ErrorType]]) -> Result[MappedValueType, ErrorType]
¶
Apply fn to the wrapped value and return its Result directly.
Unlike :meth:map, fn itself returns a Result, so you can chain
multiple fallible operations without nesting Ok(Ok(...)).
Source code in src/forging_blocks/foundation/result/ok.py
get_value_or(default: ValueType) -> ValueType
¶
Return the wrapped value, ignoring default.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
default
|
ValueType
|
Ignored — this Result is a success. |
required |
Returns:
| Type | Description |
|---|---|
ValueType
|
The unwrapped success value. |
Source code in src/forging_blocks/foundation/result/ok.py
get_value_or_else(fn: Callable[[ErrorType], ValueType]) -> ValueType
¶
Return the wrapped value, ignoring fn.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[ErrorType], ValueType]
|
Ignored — this Result is a success. |
required |
Returns:
| Type | Description |
|---|---|
ValueType
|
The unwrapped success value. |