fork download
  1. type MessageKey = { id: string; number: string }
  2.  
  3. type Substitution = Map<MessageKey, MessageKey>
  4.  
  5. type Message =
  6. { id: string
  7. number: string
  8. message: string
  9. message_v1: string
  10. message_v2: string
  11. message_v3: string
  12. message_v4: string }
  13.  
  14. let messagesToChange: Message list =
  15. [ { id = "SY"
  16. number = "530"
  17. message = "Es ist eine Ausnahme aufgetreten"
  18. message_v1 = ""
  19. message_v2 = ""
  20. message_v3 = ""
  21. message_v4 = "" }
  22. { id = "SY"
  23. number = "499"
  24. message = "A B C D"
  25. message_v1 = "A"
  26. message_v2 = "B"
  27. message_v3 = "C"
  28. message_v4 = "D" } ]
  29.  
  30. let substitutions: Substitution =
  31. Map
  32. [ ({ id = "SY"; number = "530" }, { id = "SY"; number = "000" })
  33. ({ id = "SY"; number = "499" }, { id = "ABC"; number = "999" }) ]
  34.  
  35. let Key (message: Message) : MessageKey =
  36. { id = message.id
  37. number = message.number }
  38.  
  39. let replace (substitutions: Substitution) (message: Message) : Message =
  40. let r: MessageKey option = Map.tryFind (Key message) substitutions in
  41.  
  42. match r with
  43. | Some(r) ->
  44. { message with
  45. id = r.id
  46. number = r.number }
  47. | None -> message
  48.  
  49. let result = List.map (replace substitutions) messagesToChange
  50.  
Success #stdin #stdout 0.09s 31304KB
stdin
Standard input is empty
stdout
Standard output is empty