6 people like it.

Active Pattern FizzBuzz

FizzBuzz using Active Patterns.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
open System
let (|Fizz|None|) x =
  if x % 3 = 0 then Fizz else None

let (|Buzz|None|) x =
  if x % 5 = 0 then Buzz else None

let fizzbuzz x =
  match x with
    | Fizz & Buzz -> "FizzBuzz"
    | Fizz -> "Fizz"
    | Buzz -> "Buzz"
    | _ -> x.ToString()

let start xs =
  for i in xs do
    printfn "%s" (fizzbuzz i)
namespace System
union case Option.None: Option<'T>
val x : int
Multiple items
union case Option.None: Option<'T>

--------------------
active recognizer None: int -> Choice<unit,unit>

Full name: Script.( |Fizz|None| )
active recognizer None: int -> Choice<unit,unit>

Full name: Script.( |Fizz|None| )
val fizzbuzz : x:int -> string

Full name: Script.fizzbuzz
active recognizer Fizz: int -> Choice<unit,unit>

Full name: Script.( |Fizz|None| )
active recognizer Buzz: int -> Choice<unit,unit>

Full name: Script.( |Buzz|None| )
Int32.ToString() : string
Int32.ToString(provider: IFormatProvider) : string
Int32.ToString(format: string) : string
Int32.ToString(format: string, provider: IFormatProvider) : string
val start : xs:seq<int> -> unit

Full name: Script.start
val xs : seq<int>
val i : int
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Raw view New version

More information

Link:http://fssnip.net/qf
Posted:4 years ago
Author:Nathan Smith
Tags: fizzbuzz