Replies: 1 comment 5 replies
-
I like both ideas, I think they are both valid in terms of enforcing a typed collection at runtime. From a static analysis point of view I think something closer to "Idea 1" is more feasible, because it's likely that a separate class with different type hints for its interfaces would be needed. For example, for Appendable the type of elements that can be appended cannot be |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm just writing here my raw ideas about how to provide a TypedCollection class.
Idea 1 (tested and working)
We could simply provide a new
TypedCollection
class that would decorateCollection
and where the::getIterator()
method would be wrapped with a newTypedIterator
such as:Idea 2 (tested and working)
Add a new operation
Collection::strict(callable $callback)
that would throw an exception as soon as the$callback
returnfalse
.Example of what the
Strict
operation could beBeta Was this translation helpful? Give feedback.
All reactions