Learning F#, created a somewhat elaborate fizzbuzz-builder implementation to see if I'm starting to "get" F# and thinking functionally:
type FBCase = FBCase of (int * string)
let makeFBCase num = FBCase (num, "")
let unpackFBCase case =
match case with
| FBCase (num, str) when str = "" -> num |> string
| FBCase (_, str) -> str
let fbBuilder (num) (str:string) input =
match input with
| FBCase (x, y) when x % num = 0 -> FBCase (x, y+str)
| _ -> input
let createFBFunc input = fbBuilder (fst input) (snd input)
let createFBPipeline inputList =
inputList
|> List.map createFBFunc
|> List.reduce (>>)
let createFBPattern inputList =
makeFBCase
>> (inputList |> createFBPipeline)
>> unpackFBCase
let fizzBuzz = createFBPattern [(3, "Fizz"); (5, "Buzz")]
let fizzBuzzBaz = createFBPattern [(3, "Fizz"); (5, "Buzz"); (7, "Baz")]
let fizzBuzzBazQuux = createFBPattern [(3, "Fizz"); (5, "Buzz"); (7, "Baz"); (11, "Quux")]
[1..100]
|> List.iter (fizzBuzz >> printfn "%A")
[1..100]
|> List.iter (fizzBuzzBaz >> printfn "%A")
[1..100]
|> List.iter (fizzBuzzBazQuux >> printfn "%A")
Where is it obvious that I'm not thinking functionally? What could I change to make a more idiomatic F#-style program? (Note that I don't really "get" monads or workflows yet, although I'm aware they exist).