How can I reduce the number of layers of pattern matches?
Now there are 3 layers of nested pattern matches, which I think is a lot of repeated work. I want to reduce it to 1 pattern match, is it possible? How to do it?
type test4 = {
C: int option
}
type test3 = {
B: test4 option
}
type test2 = {
A: test3 option
}
let testANone = {
A=None
}
let testBNone = {
A=Some {
B=None
}
}
let testCNone ={
A=Some {
B=Some {
C= None
}
}
}
let testCSome ={
A=Some {
B=Some {
C= Some 1000
}
}
}
let nestedmatch (t:test2) =
match t.A with
|Some A ->
match A.B with
|Some B ->
match B.C with
|Some C ->printfn $"{C}"
|_ -> printfn "None at C"
|_ ->printfn "None at B"
|_->printfn "None at A"