# Working with result type

**URL:** <https://forums.fsharp.org/t/working-with-result-type/3488>\
**Category:** General\
**Tags:** beginners\
**Created:** [December 27, 2023, 11:17am UTC](https://forums.fsharp.org/t/working-with-result-type/3488 "2023-12-27T11:17:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![FabBadDog](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/fabbaddog/32/1260_2.png) [@FabBadDog](https://forums.fsharp.org/u/FabBadDog)\
**Post date:** [December 27, 2023, 11:17am UTC](https://forums.fsharp.org/t/working-with-result-type/3488/1 "2023-12-27T11:17:52Z")

</div>

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:

```auto
            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

---

<div class="post-metadata">

**Author:** ![ntwilson](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/ntwilson/32/984_2.png) [@ntwilson](https://forums.fsharp.org/u/ntwilson)\
**Post date:** [December 27, 2023, 2:48pm UTC](https://forums.fsharp.org/t/working-with-result-type/3488/2 "2023-12-27T14:48:51Z")

</div>

If you pull in a result computation expression, like from FSharpx.Extras, you could do it as

```auto
open FSharpx

result {
  let! id = id
  let! content = content
  let! priority = priority
  let! isCompleted = isCompleted
  let! description = description
  let! order = order
  let! projectId = projectId
  return 
    { Id = id
      Title = content
      Priority = priority
      IsCompleted = isCompleted
      Description = description
      Order = order
      ProjectId = projectId }
}

```

---

<div class="post-metadata">

**Author:** ![FabBadDog](https://yyz2.discourse-cdn.com/flex030/user_avatar/forums.fsharp.org/fabbaddog/32/1260_2.png) [@FabBadDog](https://forums.fsharp.org/u/FabBadDog)\
**Post date:** [December 27, 2023, 3:30pm UTC](https://forums.fsharp.org/t/working-with-result-type/3488/3 "2023-12-27T15:30:28Z")

</div>

Thank you! Works like a charm!
