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

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -