Composes inner ``Result`` with ``IOResult`` returning function. Can be useful when you need an access to both states of the result. .. code:: python >>> from returns.io import IOResult, IOSuccess, IOFailure >>> from returns.result import Result
(
self,
function: Callable[
[Result[_ValueType_co, _ErrorType_co]],
Kind2['IOResult', _NewValueType, _ErrorType_co],
],
)
| 611 | return IO(self._inner_value.failure()) |
| 612 | |
| 613 | def compose_result( |
| 614 | self, |
| 615 | function: Callable[ |
| 616 | [Result[_ValueType_co, _ErrorType_co]], |
| 617 | Kind2['IOResult', _NewValueType, _ErrorType_co], |
| 618 | ], |
| 619 | ) -> 'IOResult[_NewValueType, _ErrorType_co]': |
| 620 | """ |
| 621 | Composes inner ``Result`` with ``IOResult`` returning function. |
| 622 | |
| 623 | Can be useful when you need an access to both states of the result. |
| 624 | |
| 625 | .. code:: python |
| 626 | |
| 627 | >>> from returns.io import IOResult, IOSuccess, IOFailure |
| 628 | >>> from returns.result import Result |
| 629 | |
| 630 | >>> def count(container: Result[int, int]) -> IOResult[int, int]: |
| 631 | ... return IOResult.from_result( |
| 632 | ... container.map(lambda x: x + 1).alt(abs), |
| 633 | ... ) |
| 634 | |
| 635 | >>> assert IOSuccess(1).compose_result(count) == IOSuccess(2) |
| 636 | >>> assert IOFailure(-1).compose_result(count) == IOFailure(1) |
| 637 | |
| 638 | """ |
| 639 | return dekind(function(self._inner_value)) |
| 640 | |
| 641 | def __iter__(self) -> Iterator[_ValueType_co]: |
| 642 | """API for :ref:`do-notation`.""" |