@@ -184,13 +184,13 @@ Let's see how it works:
184
184
.. code :: python
185
185
186
186
>> > from returns.primitives.hkt import Kind1
187
- >> > from returns.interfaces.container import Container1
187
+ >> > from returns.interfaces.container import ContainerN
188
188
>> > from typing import TypeVar
189
189
190
- >> > T = TypeVar(' T' , bound = Container1 )
190
+ >> > T = TypeVar(' T' , bound = ContainerN )
191
191
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 )
194
194
195
195
Now, this will work almost correctly!
196
196
Why almost? Because the revealed type will be ``Kind1 ``.
@@ -210,8 +210,8 @@ The final solution is to decorate ``to_str`` with ``@kinded``:
210
210
>> > from returns.primitives.hkt import kinded
211
211
212
212
>> > @ 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 )
215
215
216
216
Now, it will be fully working:
217
217
@@ -222,7 +222,7 @@ Now, it will be fully working:
222
222
223
223
And the thing about this approach is that it will be:
224
224
225
- 1. Fully type-safe. It works with correct interface ``Container1 ``,
225
+ 1. Fully type-safe. It works with correct interface ``ContainerN ``,
226
226
returns the correct type, has correct type transformation
227
227
2. Is opened for further extension and even custom types
228
228
0 commit comments