@@ -110,10 +110,59 @@ one for successful case, one for failing case.
110110 ... return 0.0
111111 ...
112112
113- >> > coalesce_result(handle_success, handle_failure)(Success(1 ))
114- 0.5
115- >> > coalesce_result(handle_success, handle_failure)(Failure(1 ))
116- 0.0
113+ >> > assert coalesce_result(handle_success, handle_failure)(Success(1 )) == 0.5
114+ >> > assert coalesce_result(handle_success, handle_failure)(Failure(1 )) == 0.0
115+
116+
117+ squash
118+ ------
119+
120+ squash_io
121+ ~~~~~~~~~
122+
123+ :func: `returns.converters.squash_io ` function
124+ allows to squash several ``IO `` containers together.
125+
126+ That's how it works:
127+
128+ .. code :: python
129+
130+ >> > from returns.io import IO
131+ >> > from returns.converters import squash_io
132+
133+ >> > assert squash_io(IO(' first' ), IO(' second' )) == IO((' first' , ' second' ))
134+ >> > # => revealed type of this instance is `IO[Tuple[str, str]]`
135+
136+ It might be helpful if you want
137+ to work with mutliple ``IO `` instances at the same time.
138+
139+ This approach saves you you from multiple nested ``IO.map `` calls.
140+ You can work with tuples instead like so:
141+
142+ .. code :: python
143+
144+ >> > plus = squash_io(IO(1 ), IO(' a' )).map(lambda args : args[0 ] + len (args[1 ]))
145+ >> > assert plus == IO(3 )
146+
147+ We support up to 9 typed parameters to this function.
148+
149+ squash_context
150+ ~~~~~~~~~~~~~~
151+
152+ :func: `returns.converters.squash_context ` is similar to ``squash_io ``,
153+ but works with ``RequiresContext `` container.
154+
155+ .. code :: python
156+
157+ >> > from returns.context import RequiresContext
158+ >> > from returns.converters import squash_context
159+
160+ >> > assert squash_context(
161+ ... RequiresContext.from_value(1 ),
162+ ... RequiresContext.from_value(' a' ),
163+ ... )(... ) == RequiresContext.from_value((1 , ' a' ))(... )
164+ >> > # revealed type is: RequiresContext[Any, Tuple[int, str]]
165+
117166
118167
119168 API Reference
@@ -123,11 +172,12 @@ API Reference
123172
124173.. autofunction :: returns.converters.flatten
125174
126- .. autofunction :: returns.converters.coalesce_maybe
127-
128- .. autofunction :: returns.converters.coalesce_result
175+ .. autofunction :: returns.converters.squash_io
129176
130- .. autofunction :: returns.converters.coalesce_ioresult
177+ .. autofunction :: returns.converters.squash_context
131178
132179.. automodule :: returns.converters
133180 :members:
181+
182+ .. autofunction :: returns.converters.coalesce_maybe
183+
0 commit comments