@@ -184,13 +184,13 @@ Let's see how it works:
184184.. code :: python
185185
186186 >> > from returns.primitives.hkt import Kind1
187- >> > from returns.interfaces.container import Container1
187+ >> > from returns.interfaces.container import ContainerN
188188 >> > from typing import TypeVar
189189
190- >> > T = TypeVar(' T' , bound = Container1 )
190+ >> > T = TypeVar(' T' , bound = ContainerN )
191191
192- >> > def to_str (arg : Kind1[T, int ]) -> Kind1[T, str ]:
193- ... ...
192+ >> > def to_str (container : Kind1[T, int ]) -> Kind1[T, str ]:
193+ ... return container.map( str )
194194
195195 Now, this will work almost correctly!
196196Why almost? Because the revealed type will be ``Kind1 ``.
@@ -210,8 +210,8 @@ The final solution is to decorate ``to_str`` with ``@kinded``:
210210 >> > from returns.primitives.hkt import kinded
211211
212212 >> > @ kinded
213- ... def to_str (arg : Kind1[T, int ]) -> Kind1[T, str ]:
214- ... ...
213+ ... def to_str (container : Kind1[T, int ]) -> Kind1[T, str ]:
214+ ... return container.map( str )
215215
216216 Now, it will be fully working:
217217
@@ -222,7 +222,7 @@ Now, it will be fully working:
222222
223223 And the thing about this approach is that it will be:
224224
225- 1. Fully type-safe. It works with correct interface ``Container1 ``,
225+ 1. Fully type-safe. It works with correct interface ``ContainerN ``,
226226 returns the correct type, has correct type transformation
2272272. Is opened for further extension and even custom types
228228
0 commit comments