Well, to convert from a string to mappingType
, you can define a little helper function:
let convert m =
match m with
| "1-1" -> mappingType.oneToOneMapping
| _ -> mappingType.oneToManyMapping
Which will enable you to write your projection like:
let iWantThisMap =
iAmConfusedXml.GetHelpMes()
|> Seq.map (fun e -> e.Feeling, {
strength = e.Strength;
mapping = (e.Mapping.Value |> convert) })
|> Map.ofSeq
Now, there's a bit of cheating here because it's simply calling e.Mapping.Value
. This might throw an exception if e.Mapping
is None
, but it works given the data provided here, because e.Mapping
always has a value.