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

Function flatten

returns/converters.py:18–49  ·  view source on GitHub ↗

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,
    ],
)

Source from the content-addressed store, hash-verified

16
17@kinded
18def 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
52def result_to_maybe(

Callers 6

test_flattenFunction · 0.90
test_flatten_contextFunction · 0.90
test_flatten_futureFunction · 0.90
test_non_flatten_futureFunction · 0.90

Calls 1

bindMethod · 0.45

Tested by 6

test_flattenFunction · 0.72
test_flatten_contextFunction · 0.72
test_flatten_futureFunction · 0.72
test_non_flatten_futureFunction · 0.72