1 people like it.

Fun with FizzBuzz

Lazily generate fizzbuzz results and provide a test function. Parameterize the inputs and predicates.

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
let fizzbuzz n =
    match n%3, n%5 with
    | 0,0 -> "FizzBuzz"
    | 0,_ -> "Fizz"
    | _,0 -> "Buzz"
    | _   -> string n

let genfizzbuzz n = seq { for x in 1..n -> fizzbuzz x }

let testFizzBuzz n =
    genfizzbuzz n
    |> Seq.skip (n-1)
    |> Seq.head
val fizzbuzz : n:int -> string

Full name: Script.fizzbuzz
val n : int
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
val genfizzbuzz : n:int -> seq<string>

Full name: Script.genfizzbuzz
Multiple items
val seq : sequence:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Core.Operators.seq

--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>

Full name: Microsoft.FSharp.Collections.seq<_>
val x : int
val testFizzBuzz : n:int -> string

Full name: Script.testFizzBuzz
module Seq

from Microsoft.FSharp.Collections
val skip : count:int -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.skip
val head : source:seq<'T> -> 'T

Full name: Microsoft.FSharp.Collections.Seq.head
Next Version Raw view Test code New version

More information

Link:http://fssnip.net/kO
Posted:11 years ago
Author:Ryan Riley
Tags: fizzbuzz