⚙️ Result monad
This container wraps a result computation value into Ok or when the function call failed, returns Err(exception)
💻 API reference
ResultShortcutError
Bases: Exception
, t.Generic[T_error]
Parameters:
Name | Type | Description | Default |
---|---|---|---|
Exception |
_type_
|
description |
required |
t |
_type_
|
description |
required |
Source code in fateful/monad/result.py
258 259 260 261 262 263 264 265 266 267 |
|
result_shortcut(f)
summary
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
t.Callable[P_mapper, V]
|
description |
required |
Returns:
Type | Description |
---|---|
t.Callable[P, Result[T_co, T_error]]
|
t.Callable[P_mapper, Ok[V] | Err[t.Any]]: description |
Source code in fateful/monad/result.py
270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
|
sync_try(f, exc=(Exception))
Run a function that may raise an exception and return a Result type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exc |
tuple[type[T_err], ...]
|
description. Defaults to (Exception,) |
(Exception)
|
Source code in fateful/monad/result.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
|
to_result(exc=(Exception))
Decorator to convert a function that may raise an exception to a Result type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exc |
tuple[type[T_err], ...]
|
description. Defaults to (Exception,) |
(Exception)
|
Returns:
Name | Type | Description |
---|---|---|
_type_ |
t.Callable[[t.Callable[P, T_co]], t.Callable[P, Result[T_co, T_error]]]
|
description |
Source code in fateful/monad/result.py
243 244 245 246 247 248 249 250 251 252 253 254 255 |
|