Allows working with unwrapped values of containers in a safe way. .. code:: python >>> import anyio >>> from returns.future import Future >>> from returns.io import IO >>> async def main() -> bool: ... return await Future.do(
(
cls,
expr: AsyncGenerator[_NewValueType, None],
)
| 351 | |
| 352 | @classmethod |
| 353 | def do( |
| 354 | cls, |
| 355 | expr: AsyncGenerator[_NewValueType, None], |
| 356 | ) -> 'Future[_NewValueType]': |
| 357 | """ |
| 358 | Allows working with unwrapped values of containers in a safe way. |
| 359 | |
| 360 | .. code:: python |
| 361 | |
| 362 | >>> import anyio |
| 363 | >>> from returns.future import Future |
| 364 | >>> from returns.io import IO |
| 365 | |
| 366 | >>> async def main() -> bool: |
| 367 | ... return await Future.do( |
| 368 | ... first + second |
| 369 | ... async for first in Future.from_value(2) |
| 370 | ... async for second in Future.from_value(3) |
| 371 | ... ) == IO(5) |
| 372 | |
| 373 | >>> assert anyio.run(main) is True |
| 374 | |
| 375 | See :ref:`do-notation` to learn more. |
| 376 | |
| 377 | """ |
| 378 | |
| 379 | async def factory() -> _NewValueType: |
| 380 | return await anext(expr) |
| 381 | |
| 382 | return Future(factory()) |
| 383 | |
| 384 | @classmethod |
| 385 | def from_value(cls, inner_value: _NewValueType) -> 'Future[_NewValueType]': |