In F #, you can match a pattern by function signature. I want to decorate a number of functions with a function that measures the execution of a function and is called in statsd. My current function:
let WrapFunctionWithPrefix(metrics:Metric.Client.IRecorder, functionToWrap, prefix) = let metricsIdentifier = (sprintf "%s.%s" prefix Environment.MachineName) using (metrics.StartTimer(metricsIdentifier)) ( fun metrics -> functionToWrap)
As you can see above, the prefix will change, and in our application this will depend on the definition of the function. So instead of passing the measure prefix every time I want to do something like the following:
let WrapFunction metrics afunc = match afunc with | :? (int -> int) -> WrapFunctionWithPrefix(metrics, afunc, "My function 1") | :? (string -> string) -> WrapFunctionWithPrefix(metrics, afunc, "My function 2") | _ -> failwith "Unknown function def"
Is there a way to match patterns based on function signature in F #?
Any help was appreciated.
Billy
source share