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

Method do

returns/io.py:647–677  ·  view source on GitHub ↗

Allows working with unwrapped values of containers in a safe way. .. code:: python >>> from returns.io import IOResult, IOFailure, IOSuccess >>> assert IOResult.do( ... first + second ... for first in IOSuccess(2) ...

(
        cls,
        expr: Generator[_NewValueType, None, None],
    )

Source from the content-addressed store, hash-verified

645
646 @classmethod
647 def do(
648 cls,
649 expr: Generator[_NewValueType, None, None],
650 ) -> 'IOResult[_NewValueType, _NewErrorType]':
651 """
652 Allows working with unwrapped values of containers in a safe way.
653
654 .. code:: python
655
656 >>> from returns.io import IOResult, IOFailure, IOSuccess
657
658 >>> assert IOResult.do(
659 ... first + second
660 ... for first in IOSuccess(2)
661 ... for second in IOSuccess(3)
662 ... ) == IOSuccess(5)
663
664 >>> assert IOResult.do(
665 ... first + second
666 ... for first in IOFailure('a')
667 ... for second in IOSuccess(3)
668 ... ) == IOFailure('a')
669
670 See :ref:`do-notation` to learn more.
671 This feature requires our :ref:`mypy plugin <mypy-plugins>`.
672
673 """
674 try:
675 return IOResult.from_value(next(expr))
676 except UnwrapFailedError as exc:
677 return IOResult.from_result(exc.halted_container) # type: ignore
678
679 @classmethod
680 def from_typecast(

Callers

nothing calls this directly

Calls 2

from_valueMethod · 0.45
from_resultMethod · 0.45

Tested by

no test coverage detected