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

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -