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

Class IO

returns/io.py:31–229  ·  view source on GitHub ↗

Explicit container for impure function results. We also sometimes call it "marker" since once it is marked, it cannot be ever unmarked. There's no way to directly get its internal value. Note that ``IO`` represents a computation that never fails. Examples of such computat

Source from the content-addressed store, hash-verified

29
30
31class IO( # type: ignore[type-var]
32 BaseContainer,
33 SupportsKind1['IO', _ValueType_co],
34 io.IOLike1[_ValueType_co],
35):
36 """
37 Explicit container for impure function results.
38
39 We also sometimes call it "marker" since once it is marked,
40 it cannot be ever unmarked.
41 There's no way to directly get its internal value.
42
43 Note that ``IO`` represents a computation that never fails.
44
45 Examples of such computations are:
46
47 - read / write to localStorage
48 - get the current time
49 - write to the console
50 - get a random number
51
52 Use ``IOResult[...]`` for operations that might fail.
53 Like DB access or network operations.
54
55 See also:
56 - https://dev.to/gcanti/getting-started-with-fp-ts-io-36p6
57 - https://gist.github.com/chris-taylor/4745921
58
59 """
60
61 __slots__ = ()
62
63 _inner_value: _ValueType_co
64
65 #: Typesafe equality comparison with other `Result` objects.
66 equals = container_equality
67
68 def __init__(self, inner_value: _ValueType_co) -> None:
69 """
70 Public constructor for this type. Also required for typing.
71
72 .. code:: python
73
74 >>> from returns.io import IO
75 >>> assert str(IO(1)) == '<IO: 1>'
76
77 """
78 super().__init__(inner_value)
79
80 def map(
81 self,
82 function: Callable[[_ValueType_co], _NewValueType],
83 ) -> 'IO[_NewValueType]':
84 """
85 Applies function to the inner value.
86
87 Applies 'function' to the contents of the IO instance
88 and returns a new IO object containing the result.

Callers 15

awaitableMethod · 0.90
test_safe_decoratorFunction · 0.90
test_inner_valueFunction · 0.90
test_inner_valueFunction · 0.90
test_ioresult_value_orFunction · 0.90
test_unwrap_iosuccessFunction · 0.90
test_failure_iofailureFunction · 0.90
test_io_mapFunction · 0.90
test_io_bindFunction · 0.90
test_io_strFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_safe_decoratorFunction · 0.72
test_inner_valueFunction · 0.72
test_inner_valueFunction · 0.72
test_ioresult_value_orFunction · 0.72
test_unwrap_iosuccessFunction · 0.72
test_failure_iofailureFunction · 0.72
test_io_mapFunction · 0.72
test_io_bindFunction · 0.72
test_io_strFunction · 0.72
test_equalsFunction · 0.72
test_not_equalsFunction · 0.72