I have a string for which I want to use an active pattern to match against. I've noticed I have to repeat the same function invocation when the value is an input to a function. Is there a way to not have to keep calling the function?
let (|A|B|C|X|) stringValue =
match stringValue with
| value when compareCaseInsensitive stringValue "a" -> A
| value when compareCaseInsensitive stringValue "b" -> B
| value when compareCaseInsensitive stringValue "c" -> C
| _ -> X stringValue
You could define yet another active pattern for your black-box function:
let (|CCI|_|) (v: string) c =
if v.Equals(c, System.StringComparison.InvariantCultureIgnoreCase) then Some()
else None
let (|A|B|C|X|) stringValue =
match stringValue with
| CCI "a" -> A
| CCI "b" -> B
| CCI "c" -> C
| _ -> X stringValue
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With