def from_ioresult_context( cls, inner_value: 'ReaderIOResult[_NewValueType, _NewErrorType, _NewEnvType]', ) -> 'ReaderFutureResult[_NewValueType, _NewErrorType, _NewEnvType]': """ Creates new container from ``RequiresContextIOResult`` as a unit value. .. code:: python >>> import anyio >>> from returns.context import RequiresContextIOResult >>> from returns.io import IOSuccess, IOFailure >>> assert anyio.run( ... RequiresContextFutureResult.from_ioresult_context( ... RequiresContextIOResult.from_value(1), ... ), ... RequiresContextFutureResult.empty, ... ) == IOSuccess(1) >>> assert anyio.run( ... RequiresContextFutureResult.from_ioresult_context( ... RequiresContextIOResult.from_failure(1), ... ), ... RequiresContextFutureResult.empty, ... ) == IOFailure(1) """ return RequiresContextFutureResult( lambda deps: FutureResult.from_ioresult(inner_value(deps)), )
def from_ioresult( cls, inner_value: IOResult[_NewValueType, _NewErrorType], ) -> 'RequiresContextFutureResult[_NewValueType, _NewErrorType, NoDeps]': """ Creates new container with ``IOResult`` as a unit value. .. code:: python >>> import anyio >>> from returns.context import RequiresContextFutureResult >>> from returns.io import IOSuccess, IOFailure >>> assert anyio.run( ... RequiresContextFutureResult.from_ioresult(IOSuccess(1)), ... RequiresContextFutureResult.empty, ... ) == IOSuccess(1) >>> assert anyio.run( ... RequiresContextFutureResult.from_ioresult(IOFailure(1)), ... RequiresContextFutureResult.empty, ... ) == IOFailure(1) """ return RequiresContextFutureResult( lambda _: FutureResult.from_ioresult(inner_value), )
async def test_inner_value(subtests): """Ensure that coroutine correct value is preserved for all units.""" containers = [ # We have to define these values inside the test, because # otherwise `anyio` will `await` reused coroutines. # And they have to be fresh. That's why we use subtests for it. FutureResult.from_value(1), FutureResult.from_failure(1), FutureResult.from_io(IO(1)), FutureResult.from_failed_io(IO(1)), FutureResult.from_ioresult(IOSuccess(1)), FutureResult.from_ioresult(IOFailure(1)), FutureResult.from_result(Success(1)), FutureResult.from_result(Failure(1)), FutureResult.from_future(Future.from_value(1)), FutureResult.from_failed_future(Future.from_value(1)), FutureResult.from_typecast(Future.from_value(Success(1))), ] for container in containers: with subtests.test(container=container): result_inst = await container assert result_inst._inner_value._inner_value == 1 # noqa: WPS437