MCPcopy
hub / github.com/dry-python/returns / map

Method map

returns/context/requires_context.py:129–151  ·  view source on GitHub ↗

Allows to compose functions inside the wrapped container. Here's how it works: .. code:: python >>> from returns.context import RequiresContext >>> def first(lg: bool) -> RequiresContext[int, float]: ... # `deps` has `float` type here:

(
        self,
        function: Callable[[_ReturnType_co], _NewReturnType],
    )

Source from the content-addressed store, hash-verified

127 return self._inner_value(deps)
128
129 def map(
130 self,
131 function: Callable[[_ReturnType_co], _NewReturnType],
132 ) -> RequiresContext[_NewReturnType, _EnvType_contra]:
133 """
134 Allows to compose functions inside the wrapped container.
135
136 Here's how it works:
137
138 .. code:: python
139
140 >>> from returns.context import RequiresContext
141 >>> def first(lg: bool) -> RequiresContext[int, float]:
142 ... # `deps` has `float` type here:
143 ... return RequiresContext(
144 ... lambda deps: deps if lg else -deps,
145 ... )
146
147 >>> assert first(True).map(lambda number: number * 10)(2.5) == 25.0
148 >>> assert first(False).map(lambda number: number * 10)(0.1) -1.0
149
150 """
151 return RequiresContext(lambda deps: function(self(deps)))
152
153 def apply(
154 self,

Callers 1

applyMethod · 0.95

Calls 1

RequiresContextClass · 0.85

Tested by

no test coverage detected