this is what i have so far:
type u = {str : string} //some type that has some property str (for simplicity, only one)
type du=
| A of u
| B of u // some discriminated union that carries u with it
then, somewhere i have a sequence of du that i am doing distinctBy and the property to do distinct is str.
best i could come up with is this:
Seq.distinctBy (fun d -> match d with (A u|B u) -> u.str)
the code works, but i don’t like having to match on a and b of the discriminated union and would like to replace the match with something.
question is, what? 🙂
EDIT:
in my case, a and b of the discriminated union will always carry same type u with them, one solution is to get rid of du and add it’s string form to type u and simplify this whole mess, but i would like to keep it this way for now because i was going to do matches and such on the a and b…
How about doing the match one time as a property of du?
However, I have a couple ideas which may model the relationship between u and du better while satisfying your “EDIT” concerns. One way is simply using tuples:
Another way is to switch it around and add du to u: