Skip to content

Add iteration capability to SegmentingContainer #20

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

Draft
wants to merge 2 commits into
base: 0.1.x
Choose a base branch
from

Conversation

XedinUnknown
Copy link
Member

This is an experimental attempt to make SegmentingContainer iterable.

Problems

The main problem that this presents can be described in the following way:

  1. If a ContainerInterface is given, how can a decorator iterate over its members? Spoiler: it cannot.
  2. If additional support is provided in case that ContainerInterface is also Traversable (such as MapInterface), how does one switch determine what the next element is, since the inner container will enumerate all members and not only those that begin with the root key?
    • Can refuse iteration (expose no further elements) if the next inner key does not match the root key (this is the approach taken here).
    • Can also continue scanning elements until one matching the root key is found. But this may require many iterations, and is therefore not performant: it may need to scan thousands of elements before the next valid key is found, or even scan them for nothing if there are still elements but no further valid keys. Also, this will hang with an infinite iterator.
  3. If the root is Traversable, how does one indicate that for the return value of get() in a type-safe way? SegmentingIterator#get() returns copies of itself. And itself is either traversable or not, which means that all retrieved segments are either traversable or not. For proper typing, some would need to be traversable, and some not - depending on whether the inner container has multiple items that start with the root key.

More Problems

This also opens questions like these:

  1. How does one separate the capabilities of key retrieval and of iteration, such that the latter can extend the former?

  2. In general, how does one extend functionality of a type in a maintainable way, if the type it is extending limits information about the value it wraps - information that is critical to the extension?

    Example. A SegmentingContainer allows reading information by a specific key only. A SegmentingMap (an iterable segmenting container) would need to iterate over the data in the SegmentingContainer. But it canot do that, because it is agnostic of the actual data storage, and the container it wraps does not enumerate its members - in fact, they may not be enumerable at all.

Inheritance and compile-time composition are also available options. However, this would reduce maintainability, and add complexity.

@XedinUnknown XedinUnknown added the enhancement New feature or request label Feb 3, 2021
@XedinUnknown XedinUnknown added this to the 0.1 milestone Feb 3, 2021
@XedinUnknown XedinUnknown self-assigned this Feb 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant