type MessageKey = { id: string; number: string }
type Substitution = Map<MessageKey, MessageKey>
type Message =
{ id: string
number: string
message: string
message_v1: string
message_v2: string
message_v3: string
message_v4: string }
let messagesToChange: Message list =
[ { id = "SY"
number = "530"
message = "Es ist eine Ausnahme aufgetreten"
message_v1 = ""
message_v2 = ""
message_v3 = ""
message_v4 = "" }
{ id = "SY"
number = "499"
message = "A B C D"
message_v1 = "A"
message_v2 = "B"
message_v3 = "C"
message_v4 = "D" } ]
let substitutions: Substitution =
Map
[ ({ id = "SY"; number = "530" }, { id = "SY"; number = "000" })
({ id = "SY"; number = "499" }, { id = "ABC"; number = "999" }) ]
let Key (message: Message) : MessageKey =
{ id = message.id
number = message.number }
let replace (substitutions: Substitution) (message: Message) : Message =
let r: MessageKey option = Map.tryFind (Key message) substitutions in
match r with
| Some(r) ->
{ message with
id = r.id
number = r.number }
| None -> message
let result = List.map (replace substitutions) messagesToChange
dHlwZSBNZXNzYWdlS2V5ID0geyBpZDogc3RyaW5nOyBudW1iZXI6IHN0cmluZyB9Cgp0eXBlIFN1YnN0aXR1dGlvbiA9IE1hcDxNZXNzYWdlS2V5LCBNZXNzYWdlS2V5PgoKdHlwZSBNZXNzYWdlID0KICAgIHsgaWQ6IHN0cmluZwogICAgICBudW1iZXI6IHN0cmluZwogICAgICBtZXNzYWdlOiBzdHJpbmcKICAgICAgbWVzc2FnZV92MTogc3RyaW5nCiAgICAgIG1lc3NhZ2VfdjI6IHN0cmluZwogICAgICBtZXNzYWdlX3YzOiBzdHJpbmcKICAgICAgbWVzc2FnZV92NDogc3RyaW5nIH0KCmxldCBtZXNzYWdlc1RvQ2hhbmdlOiBNZXNzYWdlIGxpc3QgPQogICAgWyB7IGlkID0gIlNZIgogICAgICAgIG51bWJlciA9ICI1MzAiCiAgICAgICAgbWVzc2FnZSA9ICJFcyBpc3QgZWluZSBBdXNuYWhtZSBhdWZnZXRyZXRlbiIKICAgICAgICBtZXNzYWdlX3YxID0gIiIKICAgICAgICBtZXNzYWdlX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