Created
October 13, 2014 04:22
-
-
Save bbhoss/01ca3c31877d88d33238 to your computer and use it in GitHub Desktop.
FizzBuzz in F#
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
// DivisibleBy Active Pattern special syntax for defining named patterns that can partition data | |
let (|DivisibleBy|_|) divisor i = | |
if i % divisor = 0 then Some () else None | |
// Use the pattern, easy. | |
for i in 1..100 do | |
match i with | |
| DivisibleBy 3 & DivisibleBy 5 -> printfn "FizzBuzz" | |
| DivisibleBy 3 -> printfn "Fizz" | |
| DivisibleBy 5 -> printfn "Buzz" | |
| _ -> printfn "%d" i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment