paulirwin commented on issue #279:
URL: https://github.com/apache/lucenenet/issues/279#issuecomment-2455506582

   I looked into the remaining types a little bit, and none of them map cleanly 
to `IEnumerable<T>`, unless we wanted to add an _additional_ `IEnumerable<T>` 
interface to them instead of trying to replace their Iterator-ness.
   
   ## DocIdSetIterator (and all of its subclasses)
   
   Apart from the monumental amount of work here if we were to change this 
design in a breaking way (with well over 100 derived types), DocIdSetIterator 
is perhaps the closest of the three remaining types to being able to cleanly 
map to `IEnumerable<T>`. `NextDoc()` maps pretty cleanly to the 
`IEnumerator<int>` pattern. I think our best path is going to be adding 
`IEnumerable<T>` here in a non-breaking way, rather than trying to change the 
existing implementation. That way, anyone that wants to enumerate over it may 
do so, but the existing methods are not affected.
   
   A quick implementation on DocIdSetIterator might look like:
   
   ```c#
   public IEnumerator<int> GetEnumerator() => new DocIdSetEnumerator(this);
   
   IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
   
   private class DocIdSetEnumerator : IEnumerator<int>
   {
       private readonly DocIdSetIterator outerInstance;
       private int current;
   
       public DocIdSetEnumerator(DocIdSetIterator outerInstance)
       {
           this.outerInstance = outerInstance;
           current = -1;
       }
   
       public int Current => current;
   
       object IEnumerator.Current => current;
   
       public void Dispose()
       {
       }
   
       public bool MoveNext()
       {
           current = outerInstance.NextDoc();
   
           return current != NO_MORE_DOCS;
       }
   
       public void Reset()
       {
           throw new System.NotSupportedException();
       }
   }
   ```
   
   This way, all subclasses will automatically inherit this behavior.
   
   If that design sounds good, I can get a PR for that.
   
   ## CharArrayIterator 
   
   I believe this type is what was referred to as `CharacterIterator` in 
@NightOwl888's last post from 2020, but let me know if I'm wrong. This type 
supports bidirectional iteration, and I think there is a nice symmetry 
currently with `Next` and `Previous`. I don't think it's a good idea for us to 
change this to support `IEnumerable<char>`, although again I could see adding 
an implementation similar to the one above for DocIdSetIterator that just calls 
`Next` on the CharArrayIterator.
   
   ## BreakIterator
   
   I'm assuming this is referring to BreakIterator in ICU4N, in which case that 
should be an issue there, although similarly to CharArrayIterator, it has a 
nice bidirectional symmetry currently. I think we should keep its existing 
design, and just consider adding `IEnumerable<int>` to it in a non-breaking way.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@lucenenet.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to