Skip to content

Instantly share code, notes, and snippets.

@zeux
Created January 4, 2013 23:26
Show Gist options
  • Save zeux/4458432 to your computer and use it in GitHub Desktop.
Save zeux/4458432 to your computer and use it in GitHub Desktop.
namespace Collections
open System
open System.Collections
[<AbstractClass>]
type LazyList<'T>() =
static let notimpl () = raise $ NotImplementedException()
abstract member Item: int -> 'T
abstract member Count: int
interface IList with
member this.Count = this.Count
member this.Item
with get index = box $ this.Item index
and set index value = notimpl ()
member this.IsReadOnly = true
member this.IsFixedSize = false
member this.GetEnumerator() =
let index = ref -1
{ new IEnumerator with
member e.Current = box $ this.Item !index
member e.MoveNext () = incr index; !index < this.Count
member e.Reset () = index := 0
}
member this.SyncRoot = notimpl ()
member this.IsSynchronized = true
member this.IndexOf(item) = -1
member this.Contains(item) = false
member this.Add(item) = notimpl ()
member this.Clear() = notimpl ()
member this.CopyTo(array, arrayIndex) = notimpl ()
member this.Insert(index, item) = notimpl ()
member this.Remove(item) = notimpl ()
member this.RemoveAt(index) = notimpl ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment