Why does Fsharp.Core use GetEnumerator instead
I was looking at implementing F # Seq methods - https://github.com/fsharp/fsharp/blob/master/src/fsharp/FSharp.Core/seq.fs .
Here's an example of a scan implementation:
[<CompiledName("Scan")>]
let scan<'T,'State> f (z:'State) (source : seq<'T>) =
checkNonNull "source" source
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
seq { let zref = ref z
yield !zref
use ie = source.GetEnumerator()
while ie.MoveNext() do
zref := f.Invoke(!zref, ie.Current)
yield !zref }
It gets an enumerator and uses a while loop to iterate (it should call MoveNext).
Can't this be changed?
[<CompiledName("Scan")>]
let scan<'T,'State> f (z:'State) (source : seq<'T>) =
checkNonNull "source" source
let f = OptimizedClosures.FSharpFunc<_,_,_>.Adapt(f)
seq { let zref = ref z
yield !zref
for i in source do
zref := f.Invoke(!zref, i)
yield !zref }
What does the for loop use.
Is it just that someone with an odd coding style wrote this code and no one changed it?
+3
source to share
No one has answered this question yet
Check out similar questions: