MCPcopy Index your code
hub / github.com/dry-python/returns / bind_awaitable

Method bind_awaitable

returns/future.py:865–898  ·  view source on GitHub ↗

Allows to compose a container and a regular ``async`` function. This function should return plain, non-container value. See :meth:`~FutureResult.bind_async` to bind ``async`` function that returns a container. .. code:: python >>> import anyio

(
        self,
        function: Callable[[_ValueType_co], Awaitable[_NewValueType]],
    )

Source from the content-addressed store, hash-verified

863 bind_async_future_result = bind_async
864
865 def bind_awaitable(
866 self,
867 function: Callable[[_ValueType_co], Awaitable[_NewValueType]],
868 ) -> 'FutureResult[_NewValueType, _ErrorType_co]':
869 """
870 Allows to compose a container and a regular ``async`` function.
871
872 This function should return plain, non-container value.
873 See :meth:`~FutureResult.bind_async`
874 to bind ``async`` function that returns a container.
875
876 .. code:: python
877
878 >>> import anyio
879 >>> from returns.future import FutureResult
880 >>> from returns.io import IOSuccess, IOFailure
881
882 >>> async def coro(x: int) -> int:
883 ... return x + 1
884
885 >>> assert anyio.run(
886 ... FutureResult.from_value(1).bind_awaitable(coro).awaitable,
887 ... ) == IOSuccess(2)
888 >>> assert anyio.run(
889 ... FutureResult.from_failure(1).bind_awaitable(coro).awaitable,
890 ... ) == IOFailure(1)
891
892 """
893 return FutureResult(
894 _future_result.async_bind_awaitable(
895 function,
896 self._inner_value,
897 )
898 )
899
900 def bind_result(
901 self,

Callers

nothing calls this directly

Calls 1

FutureResultClass · 0.85

Tested by

no test coverage detected