Hi all,
I have a section in my code where I build a record from multiple fields. The fields are wrapped into Results. The resulting record should also be a Result, containing either the record or the first error from one of the fields.
Now I created this abomination:
match id, content, priority, isCompleted, description, order, projectId with
| Result.Ok id,
Result.Ok content,
Result.Ok priority,
Result.Ok isCompleted,
Result.Ok description,
Result.Ok order,
Result.Ok projectId ->
Result.Ok
{ Id = id
Title = content
Priority = priority
IsCompleted = isCompleted
Description = description
Order = order
ProjectId = projectId }
| Result.Error e, _, _, _, _, _, _ -> Result.Error e
| _, Result.Error e, _, _, _, _, _ -> Result.Error e
| _, _, Result.Error e, _, _, _, _ -> Result.Error e
| _, _, _, Result.Error e, _, _, _ -> Result.Error e
| _, _, _, _, Result.Error e, _, _ -> Result.Error e
| _, _, _, _, _, Result.Error e, _ -> Result.Error e
| _, _, _, _, _, _, Result.Error e -> Result.Error e
For ASCII art enthusiasts this might look pleasing, but from a code perspective?
Please anyone tell me that there is a much better way to do this!
Thx