Skip to content

Instantly share code, notes, and snippets.

@kos59125
Created July 11, 2013 11:50
Show Gist options
  • Select an option

  • Save kos59125/5974781 to your computer and use it in GitHub Desktop.

Select an option

Save kos59125/5974781 to your computer and use it in GitHub Desktop.
Type casting IEnumerator to generic IEnumerator<>
open System
open System.Collections
open System.Collections.Generic
let cast<'a> : IEnumerator -> IEnumerator<'a> = function
| :? IEnumerator<'a> as e -> e
| e ->
{
new IEnumerator<'a> with
member __.Current = e.Current :?> 'a
interface IDisposable with
member __.Dispose () =
match e with
| :? IDisposable as d -> d.Dispose ()
| _ -> ()
interface IEnumerator with
member __.Current = e.Current
member __.MoveNext () = e.MoveNext ()
member __.Reset () = e.Reset ()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment