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

Method bind

returns/future.py:782–817  ·  view source on GitHub ↗

Applies 'function' to the result of a previous calculation. 'function' should accept a single "normal" (non-container) argument and return ``Future`` type object. .. code:: python >>> import anyio >>> from returns.future import FutureResult

(
        self,
        function: Callable[
            [_ValueType_co],
            Kind2['FutureResult', _NewValueType, _ErrorType_co],
        ],
    )

Source from the content-addressed store, hash-verified

780 )
781
782 def bind(
783 self,
784 function: Callable[
785 [_ValueType_co],
786 Kind2['FutureResult', _NewValueType, _ErrorType_co],
787 ],
788 ) -> 'FutureResult[_NewValueType, _ErrorType_co]':
789 """
790 Applies 'function' to the result of a previous calculation.
791
792 'function' should accept a single "normal" (non-container) argument
793 and return ``Future`` type object.
794
795 .. code:: python
796
797 >>> import anyio
798 >>> from returns.future import FutureResult
799 >>> from returns.io import IOSuccess, IOFailure
800
801 >>> def bindable(x: int) -> FutureResult[int, str]:
802 ... return FutureResult.from_value(x + 1)
803
804 >>> assert anyio.run(
805 ... FutureResult.from_value(1).bind(bindable).awaitable,
806 ... ) == IOSuccess(2)
807 >>> assert anyio.run(
808 ... FutureResult.from_failure(1).bind(bindable).awaitable,
809 ... ) == IOFailure(1)
810
811 """
812 return FutureResult(
813 _future_result.async_bind(
814 function,
815 self._inner_value,
816 )
817 )
818
819 #: Alias for `bind` method.
820 #: Part of the `FutureResultBasedN` interface.

Callers

nothing calls this directly

Calls 1

FutureResultClass · 0.85

Tested by

no test coverage detected