Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for iterable #1094

Closed
simPod opened this issue Jun 7, 2019 · 6 comments
Closed

Support for iterable #1094

simPod opened this issue Jun 7, 2019 · 6 comments

Comments

@simPod
Copy link
Contributor

simPod commented Jun 7, 2019

Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no

Here #1023 the generators and iterators support was implemented. I wonder would it be possible to support iterable?

Currently, I have to type against concrete type, eg.
* @Serializer\Type("array<T>")
* @Serializer\Type("Generator<T>")

I'd like to type as * @Serializer\Type("iterable<T>"). I suppose it could be deserialized eg. as an array when deserializing.

Would it make sense?

@goetas
Copy link
Collaborator

goetas commented Jun 7, 2019

I think here my answer is the same as for the Iterator interface, see in #1034 (comment)

@simPod
Copy link
Contributor Author

simPod commented Jun 7, 2019

I was thinking that since we're working with interface the implementation shouldn't matter (if end user respect the type ofc).

The issue is that currently it's not possible to have:

/**
 * @Serializer\Type("Generator<T>")
 * @var iterable<T>
 */
private $collection;

@var says that it expects interface so implementation doesn't matter. But serializer requires concrete type. This breaks LSP.

@goetas
Copy link
Collaborator

goetas commented Jun 7, 2019

how to deserialize @Serializer\Type("iterable<T>")?

Do you want to say that using iterable<T>, the consumer should not care if it has an array, an iterator or other, the important is that is deserialized into something "iterable" ?

@simPod
Copy link
Contributor Author

simPod commented Jun 7, 2019

Yes exactly. I don't see any better way when working with interfaces. But consumer should not care about implementation when expecting interface. 🤔

@goetas
Copy link
Collaborator

goetas commented Jun 8, 2019

You convinced me.

With this in mind, then Iterator can also be implemented, amending my comment in #1034 (comment)

@simPod
Copy link
Contributor Author

simPod commented Jun 8, 2019

Will look into it, thanks! You can assign me to this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants