Last active
January 4, 2019 19:30
-
-
Save jaypowley/9eed8345a9819bc69d4234808c8bb791 to your computer and use it in GitHub Desktop.
F# FizzBuzz with Active Patterns
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
let (|MultOf3|_|) i = if i % 3 = 0 then Some MultOf3 else None | |
let (|MultOf5|_|) i = if i % 5 = 0 then Some MultOf5 else None | |
let fizzBuzz i = | |
match i with | |
| MultOf3 & MultOf5 -> printf "FizzBuzz, " | |
| MultOf3 -> printf "Fizz, " | |
| MultOf5 -> printf "Buzz, " | |
| _ -> printf "%i, " i | |
[1..100] |> List.iter fizzBuzz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment