Last active
August 29, 2015 14:14
-
-
Save davidkellis/b58535a0f230e1a550c8 to your computer and use it in GitHub Desktop.
sequence expression headache
This file contains 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 | |
let fromIEnumerator (xs: System.Collections.Generic.IEnumerator<'x>): seq<'x> = | |
seq { | |
while xs.MoveNext() do | |
yield xs.Current | |
} | |
let fromIEnumerable (xs: System.Collections.Generic.IEnumerable<'x>): seq<'x> = fromIEnumerator (xs.GetEnumerator()) | |
let a = new ResizeArray<int>() | |
a.Add(5) | |
a.Add(6) | |
let enum = fromIEnumerable a | |
// **************** here's what happens if you call Seq.head on enum over and over: ***************************** | |
> Seq.head enum;; | |
val it : int = 5 | |
> Seq.head enum;; | |
val it : int = 6 | |
> Seq.head enum;; | |
System.ArgumentException: The input sequence was empty. | |
Parameter name: source | |
at Microsoft.FSharp.Collections.SeqModule.Head[Int32] (IEnumerable`1 source) [0x00000] in <filename unknown>:0 | |
at <StartupCode$FSI_0014>.$FSI_0014.main@ () [0x00000] in <filename unknown>:0 | |
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) | |
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 | |
Stopped due to error |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment