12/04/14 05:12:11.99
F#で演算子オーバーロードなし。
let threadLocal = new System.Threading.ThreadLocal<_>()
let makeFizzBuzz name condition (x : obj) =
match x with
| :? int as number ->
threadLocal.Value <- number
if condition number then box name else box number
| :? string as names ->
box (if condition threadLocal.Value then names + name else names)
| _ -> failwith "ロジックエラー"
let fizz = makeFizzBuzz "Fizz" (fun x -> x % 3 = 0)
let buzz = makeFizzBuzz "Buzz" (fun x -> x % 5 = 0)
let gizz = makeFizzBuzz "Gizz" (fun x -> x % 7 = 0)
> [1; 3; 5; 7; 15; 21; 35; 105] |> List.map (fun x -> gizz(buzz(fizz x)));;
val it : obj list =
[1; "Fizz"; "Buzz"; "Gizz"; "FizzBuzz"; "FizzGizz"; "BuzzGizz"; "FizzBuzzGizz"]