How to update an internal record in elms

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 exampleId, it will be as follows:

 { model | exampleId = updatedValue }

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

+4
source share
1 answer

The only way to do this in the language without unnecessary things is to destroy the external record, for example:

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

There is also a focus package that allows you to:

set ( groupOfExamples => results ) [ "whatever" ] model
+11
source

Source: https://habr.com/ru/post/1625589/


All Articles