f# - Is there a way to not have to repeat this function invocation in pattern matching? -
i have string want use active pattern match against. i've noticed have repeat same function invocation when value input function. there way not have keep calling function?
let (|a|b|c|x|) stringvalue = match stringvalue | value when comparecaseinsensitive stringvalue "a" -> | value when comparecaseinsensitive stringvalue "b" -> b | value when comparecaseinsensitive stringvalue "c" -> c | _ -> x stringvalue
you define yet active pattern black-box function:
let (|cci|_|) (v: string) c = if v.equals(c, system.stringcomparison.invariantcultureignorecase) some() else none let (|a|b|c|x|) stringvalue = match stringvalue | cci "a" -> | cci "b" -> b | cci "c" -> c | _ -> x stringvalue
Comments
Post a Comment