Created
July 11, 2013 11:50
-
-
Save kos59125/5974781 to your computer and use it in GitHub Desktop.
Type casting IEnumerator to generic IEnumerator<>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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