We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f2dc1a8 commit 5ee7d71Copy full SHA for 5ee7d71
_snippets/sequence_expressions.md
@@ -3,15 +3,14 @@ order: 15
3
title: SequenceExpressions.fs
4
excerpt_separator: <!--more-->
5
code: |
6
- // A function generating a sequence of numbers
7
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
-
+ match n with
+ | x when x % 15 = 0 -> "fizzbuzz"
+ | x when x % 3 = 0 -> "fizz"
+ | x when x % 5 = 0 -> "buzz"
+ | _ -> n.ToString()
+
+ // Tail recursion makes this as efficient as a "while" loop
15
yield! fizzBuzzSeq (n + 1)
16
}
17
0 commit comments