let chainTemplate processFunction canContinue s =the input parameter s is generalized so it is just a place holder. In my simple design pattern sample, the type is an integer.
if canContinue s then
processFunction s
else s
// simple design pattern sample
let canContinueF _ = trueIn the real world sample, s is actually a tuple type.
let processF x = x + 1
// real world problem
let canContinueF (v,unitNameIndex) = v >= unit && unitNameIndex < unitNames.Length-1
let processF (x, unitNameIndex) = (x / unit, unitNameIndex+1)
F#'s automatic generalization feature almost makes my template pattern retired.
If you want to implement the same feature in C#, seems that you have to use generic function. It is true that C# can do the same thing, but readability and productivity will be much lower than the F# version.
No comments:
Post a Comment