Joins two nested containers together. Please, note that it will not join two ``Failure`` for ``Result`` case or two ``Nothing`` for ``Maybe`` case (or basically any two error types) together. .. code:: python >>> from returns.converters import flatten >>> from
(
container: KindN[
_BindableKind,
KindN[_BindableKind, _FirstType, _SecondType, _ThirdType],
_SecondType,
_ThirdType,
],
)
| 16 | |
| 17 | @kinded |
| 18 | def flatten( |
| 19 | container: KindN[ |
| 20 | _BindableKind, |
| 21 | KindN[_BindableKind, _FirstType, _SecondType, _ThirdType], |
| 22 | _SecondType, |
| 23 | _ThirdType, |
| 24 | ], |
| 25 | ) -> KindN[_BindableKind, _FirstType, _SecondType, _ThirdType]: |
| 26 | """ |
| 27 | Joins two nested containers together. |
| 28 | |
| 29 | Please, note that it will not join |
| 30 | two ``Failure`` for ``Result`` case |
| 31 | or two ``Nothing`` for ``Maybe`` case |
| 32 | (or basically any two error types) together. |
| 33 | |
| 34 | .. code:: python |
| 35 | |
| 36 | >>> from returns.converters import flatten |
| 37 | >>> from returns.io import IO |
| 38 | >>> from returns.result import Failure, Success |
| 39 | |
| 40 | >>> assert flatten(IO(IO(1))) == IO(1) |
| 41 | |
| 42 | >>> assert flatten(Success(Success(1))) == Success(1) |
| 43 | >>> assert flatten(Failure(Failure(1))) == Failure(Failure(1)) |
| 44 | |
| 45 | See also: |
| 46 | - https://bit.ly/2sIviUr |
| 47 | |
| 48 | """ |
| 49 | return container.bind(identity) |
| 50 | |
| 51 | |
| 52 | def result_to_maybe( |