returns icon indicating copy to clipboard operation
returns copied to clipboard

Consider adding `to_iterable` converter

Open sobolevn opened this issue 4 years ago • 6 comments

After #244 we now have .from_iterable constructor on every container.

We should also add to_iterable(container: Container[Sequence[T]]) -> Iterable[Container[T]]: (where Container is just an alias, we should support types for all existing containers). So, this will allow us to construct and deconstruct values easily.

sobolevn avatar May 28 '20 11:05 sobolevn

I am really tired for now. Let's move it to the next release.

sobolevn avatar Jun 01 '20 18:06 sobolevn

We have a problem with HKT here, it can't convert Sequence[Kind1[_ContainerKind, _FirstType]] to Sequence[Container[_FirstType]]!

@kinded
def to_iterable(
    container: KindN[
        _ContainerKind, Sequence[_FirstType], _SecondType, _ThirdType
    ]
) -> Sequence[KindN[_ContainerKind, _FirstType, _SecondType, _ThirdType]]:
    ...

mypy output:

returns/converters.py:97: error: Value of type variable "_FunctionType" of "kinded" cannot be "Callable[[KindN[_ContainerKind, Sequence[_FirstType], _SecondType, _ThirdType]], Sequence[KindN[_ContainerKind, _FirstType, _SecondType, _ThirdType]]]"

Do you want to open an issue for this?

thepabloaguilar avatar Sep 05 '20 04:09 thepabloaguilar

Ok, I see. @kinded forces us to have KindN as a return type. I think, that this is a correct behaviour. Not a bug.

Any ideas on how to support it?

sobolevn avatar Sep 05 '20 08:09 sobolevn

I don't have any ideas 😞

thepabloaguilar avatar Sep 14 '20 19:09 thepabloaguilar

Ok, we should change how @kinded works in the future. Because we can and will have cases when we need wrapped expressions like List[KindN[...]. Today I have tried to write Maybe[KindN[...]], but I was not able to do that. That's sad.

But, to fully support this, we need https://github.com/python/mypy/issues/9001 to be released.

sobolevn avatar Sep 25 '20 14:09 sobolevn

I'm excited waiting for the next mypy release, should be fixed at least three issues here hahaha

thepabloaguilar avatar Sep 25 '20 14:09 thepabloaguilar