diff --git a/ArrayStream.cs b/ArrayStream.cs new file mode 100644 index 0000000..dfbaf67 --- /dev/null +++ b/ArrayStream.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace ln.collections +{ + public class ArrayStream + { + public T[] Elements { get; } + public int Position { get; set; } + + public ArrayStream(T[] elements) + { + Elements = elements; + Position = 0; + } + public ArrayStream(IEnumerable elements) + { + Elements = elements.ToArray(); + Position = 0; + } + + public T Current => Elements[Position]; + public T Next() => Next(1); + public T Next(int forward) => Elements[Position + 1 + forward]; + + public bool MoveNext() + { + if (Position >= Elements.Length) + throw new EndOfStreamException(); + + Position++; + return (Position < Elements.Length); + } + + public bool EndOfStream => (Position < Elements.Length); + + } +}