-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Adding common interface implemented by Map and Vector that is mutable and iterable #7586
base: master
Are you sure you want to change the base?
Conversation
…d IndexAccess for mutable, key-iterable collections (Map and Vector at the moment).
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at [email protected]. Thanks! If you are contributing on behalf of someone else (eg your employer): the individual CLA is not sufficient - use https://developers.facebook.com/opensource/cla?type=company instead. Contact [email protected] if you have any questions. |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
…ontainer with HHVM.
@acrylic-origami updated the pull request - view changes |
@mofarrell has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
KeyedContainer was introduced to be a union of Hack Collections and PHP arrays. This requires adding special support in the runtime to have arrays behave as instances of KeyedContainer. Do you imagine arrays also being instances of MutableKeyContainer? |
@dlreeves That's a good point. I don't include them because they don't implement
For now, I figured |
@sgolemon was thinking of this a long while back - any comments, and still have a copy of the diagram? |
If it doesn't support arrays then I wonder if a mutable version of Indexish would be better. At one point we allowed Indexish to be modified with |
@dlreeves Are you proposing reviving this historic mutable Also, did this mutable |
@acrylic-origami - Ok took a look at the type hierarchy again. Would having |
@dlreeves Well, |
https://pbs.twimg.com/media/C_pNhu3XgAAibNw.jpg |
At the moment, functions with nullable Disposable arguments can't pass the typechecker (unless the argument isn't referenced at all), since `is_null` trips Typing[4188].
@acrylic-origami has updated the pull request. Re-import the pull request |
MutableMap
andMutableVector
both already implementKeyedContainer
andIndexAccess
. The former extendsKeyedTraversable
, while the latter gives these classes basic mutability throughset[All]
andremoveKey
.Currently, the only way to admit both
Map
andVector
to an immutable wrapper with mutable descendants is to upper-bound the collection generic type byConstIndexAccess
and refine to a mutableIndexAccess
in the descendants. For example:However, without iterability, working with the
IndexAccess
family is cumbersome, and attempts to add iterability get messy. Keeping track of keys in a separate iterable collection, for example, leads quickly to generic hell, especially when the mutability of this collection is considered.Of the
Traversable
descendants, I'm proposingKeyedContainer
because it andIndexish
are the only common ancestors ofMap
andVector
to define an indexing method — in this case, the square bracket syntax.Indexish
is also a good candidate, but I figure that in the future, some core Hack classes might extendKeyedContainer
but notIndexish
, judging from Typing[4005] (the illegal-use-of-square-bracket-indexing error).I should mention the associated issue, #7573 .