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

Method swap

returns/io.py:371–387  ·  view source on GitHub ↗

Swaps value and error types. So, values become errors and errors become values. It is useful when you have to work with errors a lot. And since we have a lot of ``.bind_`` related methods and only a single ``.lash`` - it is easier to work with values.

(self)

Source from the content-addressed store, hash-verified

369 return self._inner_value.trace
370
371 def swap(self) -> 'IOResult[_ErrorType_co, _ValueType_co]':
372 """
373 Swaps value and error types.
374
375 So, values become errors and errors become values.
376 It is useful when you have to work with errors a lot.
377 And since we have a lot of ``.bind_`` related methods
378 and only a single ``.lash`` - it is easier to work with values.
379
380 .. code:: python
381
382 >>> from returns.io import IOSuccess, IOFailure
383 >>> assert IOSuccess(1).swap() == IOFailure(1)
384 >>> assert IOFailure(1).swap() == IOSuccess(1)
385
386 """
387 return self.from_result(self._inner_value.swap())
388
389 def map(
390 self,

Callers

nothing calls this directly

Calls 1

from_resultMethod · 0.95

Tested by

no test coverage detected