You might want to look into the Focus library: http://package.elm-lang.org/packages/evancz/focus/2.0.1/
But as you probably want to render your data as html, I would recommend you to break your data into modules and use the Elm Architecture: https://evancz.gitbooks.io/an-introduction-to-elm/content/architecture/ Anton Am Dienstag, 2. August 2016 02:18:17 UTC+2 schrieb Austin B: > > Hi, > > I come from an OOP background and trying to make the leap to keeping all > state in a single immutable data store, which has shown to be amazing as > long as the system is small, but I am having trouble scaling up to anything > beyond a toy app. > > One big challenge is trying to update nested fields. For example if I want > to change a forecast parameter in the following code: > > -- Model > type alias Forecast = > { parameters: Pf.ArpsParameters > , production: List Float > } > type alias Model = > { primaryForecast: Forecast > , secondaryForecast: Forecast > } > > -- Init > > init : (Model, Cmd Msg) > init = > ( > { primaryForecast = > { parameters = > { q = Nothing > , de = Nothing > , c = Nothing > , months = [0..48] > } > , production = [] > } > } > , Cmd.none > ) > > > I end up with code like this: > > update : Msg -> Model -> (Model, Cmd Msg) > update msg model = > let > primaryForecast = model.primaryForecast > parameters = model.primaryForecast.parameters > in > case msg of > Q string -> ({ model | primaryForecast = { primaryForecast | > parameters = { parameters | q = toMaybe (String.toFloat string) } } }, > message UpdateProduction) > De string -> ({ model | primaryForecast = { primaryForecast | > parameters = { parameters | de = toMaybe (String.toFloat string) } } }, > message UpdateProduction) > C string -> ({ model | primaryForecast = { primaryForecast | > parameters = { parameters | c = toMaybe (String.toFloat string) } }}, > message UpdateProduction) > UpdateProduction -> ... > > > This seems unnecessarily verbose, and I'm unsure whether I am turning > wrong with how I am structuring data or if I am trying to modify data > incorrectly. > > Thanks for any help! > > Austin > > -- You received this message because you are subscribed to the Google Groups "Elm Discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
