Skip to content

.Memoize() Concerns #889

Open
Open
@viceroypenguin

Description

@viceroypenguin

I see two concerns with .Memoize(), that I would like to discuss before addressing:

  • Currently, the _error field is use for both .GetEnumerator() errors and iteration errors. This is incorrect under the following scenario:
    1. Obtain an iterator via .GetEnumerator()
    2. Encounter an error during iteration via .MoveNext()
    3. Attempt to obtain a new iterator.
    • The expectation is that I would be able to get an iterator, and that it would iterate to the exception
    • The current code shares the _error field, and so I would get an error in .GetEnumerator() and not be able to iterate to the error.
  • Currently, the MemoizedEnumerable incorrectly implements the IDispose pattern
    • When an object is disposed, it should be prepared to be GC'd. All future attempts to use any aspect of the object should throw an ObjectDisposedException
    • The current code only throws an ObjectDisposedException when the object holds an open iteration after being disposed. The .Dispose() method is treated as a reset rather than an actual disposal; clearing the current cache and starting a new iteration as if .Skip() had been called on the original sequence.
    • If clearing the cache is a desired behavior, it should be done under a .Clear() method instead of .Dispose().

@leandromoh I am happy to update the code to correct these issues, but I would like to understand existing thought patterns if either of the above patterns is intended.

CC: @leandromoh

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions