5

I have this model

type alias Model = 
  { exampleId : Int
  , groupOfExamples : GroupExamples
  }

type alias GroupExamples = 
  { groupId : Int
  , results : List String
  }

In my update function, if I want to update the exampleId would be like this:

 { model | exampleId = updatedValue }

But what if I need to do to update, for example, just the results value inside of GroupExamples?

1

1 Answer 1

12

The only way to do it in the language without anything extra is to destructure the outer record like:

let
    examples = model.groupOfExamples
    newExamples = { examples | results = [ "whatever" ] }
in
    { model | groupOfExamples = newExamples }

There is also the focus package which would allow you to:

set ( groupOfExamples => results ) [ "whatever" ] model
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.