1 people like it.
Like the snippet!
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:
14:
|
let fizzbuzz pred1 pred2 (n: int) =
match pred1 n, pred2 n with
| 0,0 -> "FizzBuzz"
| 0,_ -> "Fizz"
| _,0 -> "Buzz"
| _ -> string n
let genFizzBuzz pred1 pred2 n =
seq { for x in 1..n -> fizzbuzz pred1 pred2 x }
let testFizzBuzz n =
genFizzBuzz ((%)3) ((%)5) n
|> Seq.skip (n-1)
|> Seq.head
|
val fizzbuzz : pred1:(int -> int) -> pred2:(int -> int) -> n:int -> string
Full name: Script.fizzbuzz
val pred1 : (int -> int)
val pred2 : (int -> int)
val n : int
Multiple items
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.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 : pred1:(int -> int) -> pred2:(int -> int) -> 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
More information