Let's say I have a discriminated union:
type card = Smithy | Cellar | Chapel
And a function that maps the discriminated union to some value:
let initialCardCount = function
Smithy -> 4
Cellar -> 6
Chapel -> 2
I want to generate a map containing the cost for each member of the union, like:
[(Smithy, 4); (Cellar, 6); (Chapel, 2)]
Is this possible? I'd like to be able to do something like:
List.zip (allValues f) (List.map getCost (allValues f)) |> Map.ofList
This question is helpful but it's not quite what I need; I want to be able to access the union members in memory instead of just inspecting their properties.
The reason I want to do this is so I can have a discriminated union representing all the different types of cards in a game, and a function that tells you how many of each card should be there at the start, and then easily generate the initial mapping of cards to counts. Is there a better way to do this?