Skip to content

Commit 5ee7d71

Browse files
authored
Update Sequence Expressions snippet to use implicit yields
1 parent f2dc1a8 commit 5ee7d71

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

_snippets/sequence_expressions.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ order: 15
33
title: SequenceExpressions.fs
44
excerpt_separator: <!--more-->
55
code: |
6-
// A function generating a sequence of numbers
76
let rec fizzBuzzSeq n = seq {
8-
yield
9-
match n with
10-
| x when x % 15 = 0 -> "fizzbuzz"
11-
| x when x % 3 = 0 -> "fizz"
12-
| x when x % 5 = 0 -> "buzz"
13-
| _ -> n.ToString()
14-
7+
match n with
8+
| x when x % 15 = 0 -> "fizzbuzz"
9+
| x when x % 3 = 0 -> "fizz"
10+
| x when x % 5 = 0 -> "buzz"
11+
| _ -> n.ToString()
12+
13+
// Tail recursion makes this as efficient as a "while" loop
1514
yield! fizzBuzzSeq (n + 1)
1615
}
1716

0 commit comments

Comments
 (0)