Skip to content

Instantly share code, notes, and snippets.

@mneedham
Created January 10, 2010 14:25
Show Gist options
  • Save mneedham/273535 to your computer and use it in GitHub Desktop.
Save mneedham/273535 to your computer and use it in GitHub Desktop.
let rec nums = seq { yield 1
printfn "yield 1"
for n in nums do
printfn "(for)yield %d" (n)
yield n+1 }
> Seq.take 5 nums |> Seq.iter (printfn "%d");;
1
yield 1
(for)yield 1
2
yield 1
(for)yield 1
(for)yield 2
3
yield 1
(for)yield 1
(for)yield 2
(for)yield 3
4
yield 1
(for)yield 1
(for)yield 2
(for)yield 3
(for)yield 4
5
-------
let rec nums = seq { yield 1
printfn "yield 1"
for n in nums do
printfn "(for)yield %d" (n)
yield n+1 } |> Seq.cache
> Seq.take 5 nums |> Seq.iter (printfn "%d");;
1
yield 1
(for)yield 1
2
(for)yield 2
3
(for)yield 3
4
(for)yield 4
5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment