Determines if a container was successful or not. .. code:: python >>> from returns.maybe import Some, Nothing >>> from returns.result import Failure, Success >>> from returns.io import IOSuccess, IOFailure >>> assert is_successful(Some(1)) >>> assert not is_
(container: Unwrappable[Any, Any])
| 9 | |
| 10 | # TODO: add overloads for specific types, so it can narrow them with `TypeIs` |
| 11 | def is_successful(container: Unwrappable[Any, Any]) -> bool: |
| 12 | """ |
| 13 | Determines if a container was successful or not. |
| 14 | |
| 15 | .. code:: python |
| 16 | |
| 17 | >>> from returns.maybe import Some, Nothing |
| 18 | >>> from returns.result import Failure, Success |
| 19 | >>> from returns.io import IOSuccess, IOFailure |
| 20 | |
| 21 | >>> assert is_successful(Some(1)) |
| 22 | >>> assert not is_successful(Nothing) |
| 23 | |
| 24 | >>> assert is_successful(Success(1)) |
| 25 | >>> assert not is_successful(Failure(1)) |
| 26 | |
| 27 | >>> assert is_successful(IOSuccess(1)) |
| 28 | >>> assert not is_successful(IOFailure(1)) |
| 29 | |
| 30 | This function can work with containers |
| 31 | that are instance of :class:`returns.interfaces.unwrappable.Unwrappable`. |
| 32 | |
| 33 | """ |
| 34 | try: |
| 35 | container.unwrap() |
| 36 | except UnwrapFailedError: |
| 37 | return False |
| 38 | return True |