Source code for stdlibx.option.fn.result
1from __future__ import annotations
2
3from functools import partial
4from typing import TYPE_CHECKING, Callable, TypeVar
5
6from stdlibx.option import Option, methods
7
8if TYPE_CHECKING:
9 from stdlibx.option._option import Operation
10 from stdlibx.result import Result
11
12T = TypeVar("T")
13U = TypeVar("U")
14E = TypeVar("E")
15
16
[docs]
17def ok_or(error: E) -> Operation[Option[T], Result[T, E]]:
18 return partial(methods.ok_or, error=error)
19
20
[docs]
21def ok_or_else(error: Callable[[], E]) -> Operation[Option[T], Result[T, E]]:
22 return partial(methods.ok_or_else, error=error)
23
24
[docs]
25def transpose() -> Operation[Option[Result[U, E]], Result[Option[U], E]]:
26 return methods.transpose