how to update an inner record in elm

后端 未结 1 342
春和景丽
春和景丽 2021-01-18 15:56

I have this model

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

type alias GroupExamples = 
  { groupId : Int
  , results         


        
1条回答
  •  迷失自我
    2021-01-18 16:14

    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 讨论(0)
提交回复
热议问题