plato icon indicating copy to clipboard operation
plato copied to clipboard

ISequence<T> vs IGenerator<T>

Open mlhaufe opened this issue 3 years ago • 1 comments

If every ISequence<T> has a generator, and IGenerator<T> extends ISequence<T> why are they two separate types? This seems like a distinction that doesn't make a difference as ISequence<T> has nothing else.

mlhaufe avatar Mar 12 '22 18:03 mlhaufe

I've arrived at a similar conclusion recently. Going to push an update real soon based on some concrete implementations, which does leave them distinct.

In case you are interested I got to that design point through the following observations:

  • Every sequence has a generator, which is sufficient to implement the entire LINQ library
  • Every sequence can be adapted into a generator (iter.HasValue => seq.Any(), iter.Value => seq.First(), iter.Next => seq.Skip(1)
  • Every generator can be adapted into a sequence, by (seq.Generator() => this)
  • Every LINQ operation that can be defined on sequences, could also be defined on generators (Select/Where/Aggregate/etc.)

I'll share soon the new version soon.

cdiggins avatar Mar 13 '22 17:03 cdiggins