I thought it match .. withmight work like ifinside a sequence expression:
let foo (m: 'a option) =
[ yield 'a'
match m with
| Some _ -> yield 'b'
yield 'c' ]
That is, I only need to indicate the appropriate case (s), while the failure case is treated as no-op. Unfortunately, this is not the case; an exception causes a mismatch.
I found that I can still get the desired result if I use yield!as follows:
let bar (m: 'a option) =
[ yield 'a'
match m with
| Some _ -> yield 'b'
| _ -> yield! []
yield 'c' ]
It works, but is this the best way? Just wondering if there is a more standard way to do this.
source
share