Skip to content

Instantly share code, notes, and snippets.

@bbhoss
Created October 13, 2014 04:22
Show Gist options
  • Save bbhoss/01ca3c31877d88d33238 to your computer and use it in GitHub Desktop.
Save bbhoss/01ca3c31877d88d33238 to your computer and use it in GitHub Desktop.
FizzBuzz in F#
// 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