Skip to content

Instantly share code, notes, and snippets.

@jaypowley
Last active January 4, 2019 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaypowley/9eed8345a9819bc69d4234808c8bb791 to your computer and use it in GitHub Desktop.
Save jaypowley/9eed8345a9819bc69d4234808c8bb791 to your computer and use it in GitHub Desktop.
F# FizzBuzz with Active Patterns
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