7 people like it.

Yet Another Fizz Buzz (YAFB)

Yet Another Fizz Buzz (YAFB)

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
let cycle x = Seq.initInfinite (fun _ -> x) |> Seq.concat
let zipWith f xs ys = Seq.zip xs ys |> Seq.map (fun (x,y) -> f x y)

let fizz     = seq ["";"";"fizz"]       |> cycle
let buzz     = seq ["";"";"";"";"buzz"] |> cycle
let numbers  = seq [1 .. 100]           |> Seq.map string
let fizzBuzz = zipWith (+) fizz buzz    |> zipWith max numbers

fizzBuzz |> Seq.take 20 |> Seq.toList
//val it : string list =
//  ["1"; "2"; "fizz"; "4"; "buzz"; "fizz"; "7"; "8"; "fizz"; "buzz"; "11";
//   "fizz"; "13"; "14"; "fizzbuzz"; "16"; "17"; "fizz"; "19"; "buzz"]
val cycle : x:seq<'a> -> seq<'a>

Full name: Script.cycle
val x : seq<'a>
module Seq

from Microsoft.FSharp.Collections
val initInfinite : initializer:(int -> 'T) -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.initInfinite
val concat : sources:seq<#seq<'T>> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.concat
val zipWith : f:('a -> 'b -> 'c) -> xs:seq<'a> -> ys:seq<'b> -> seq<'c>

Full name: Script.zipWith
val f : ('a -> 'b -> 'c)
val xs : seq<'a>
val ys : seq<'b>
val zip : source1:seq<'T1> -> source2:seq<'T2> -> seq<'T1 * 'T2>

Full name: Microsoft.FSharp.Collections.Seq.zip
val map : mapping:('T -> 'U) -> source:seq<'T> -> seq<'U>

Full name: Microsoft.FSharp.Collections.Seq.map
val x : 'a
val y : 'b
val fizz : seq<string>

Full name: Script.fizz
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 buzz : seq<string>

Full name: Script.buzz
val numbers : seq<string>

Full name: Script.numbers
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 fizzBuzz : seq<string>

Full name: Script.fizzBuzz
val max : e1:'T -> e2:'T -> 'T (requires comparison)

Full name: Microsoft.FSharp.Core.Operators.max
val take : count:int -> source:seq<'T> -> seq<'T>

Full name: Microsoft.FSharp.Collections.Seq.take
val toList : source:seq<'T> -> 'T list

Full name: Microsoft.FSharp.Collections.Seq.toList
Raw view New version

More information

Link:http://fssnip.net/tl
Posted:1 years ago
Author:@Functional_S
Tags: fizzbuzz , fizz , buzz , seq , lazy