Calls a wrapped function in a container on this container. .. code:: python >>> from returns.io import IOSuccess, IOFailure >>> def appliable(first: str) -> str: ... return first + 'b' >>> assert IOSuccess('a').apply( ...
(
self,
container: Kind2[
'IOResult',
Callable[[_ValueType_co], _NewValueType],
_ErrorType_co,
],
)
| 402 | return self.from_result(self._inner_value.map(function)) |
| 403 | |
| 404 | def apply( |
| 405 | self, |
| 406 | container: Kind2[ |
| 407 | 'IOResult', |
| 408 | Callable[[_ValueType_co], _NewValueType], |
| 409 | _ErrorType_co, |
| 410 | ], |
| 411 | ) -> 'IOResult[_NewValueType, _ErrorType_co]': |
| 412 | """ |
| 413 | Calls a wrapped function in a container on this container. |
| 414 | |
| 415 | .. code:: python |
| 416 | |
| 417 | >>> from returns.io import IOSuccess, IOFailure |
| 418 | |
| 419 | >>> def appliable(first: str) -> str: |
| 420 | ... return first + 'b' |
| 421 | |
| 422 | >>> assert IOSuccess('a').apply( |
| 423 | ... IOSuccess(appliable), |
| 424 | ... ) == IOSuccess('ab') |
| 425 | >>> assert IOFailure('a').apply( |
| 426 | ... IOSuccess(appliable), |
| 427 | ... ) == IOFailure('a') |
| 428 | |
| 429 | >>> assert IOSuccess('a').apply(IOFailure(1)) == IOFailure(1) |
| 430 | >>> assert IOFailure('a').apply(IOFailure('b')) == IOFailure('a') |
| 431 | |
| 432 | """ |
| 433 | if isinstance(self, IOFailure): |
| 434 | return self |
| 435 | if isinstance(container, IOSuccess): |
| 436 | return self.from_result( |
| 437 | self._inner_value.map( |
| 438 | container.unwrap()._inner_value, # noqa: SLF001 |
| 439 | ), |
| 440 | ) |
| 441 | return container # type: ignore |
| 442 | |
| 443 | def bind( |
| 444 | self, |
nothing calls this directly
no test coverage detected