A lot of the code I've written that has dealt with wrapped models has used the `as` keyword but I've found that it makes the code harder to follow because the pieces working with the unwrapped model are mixed with the pieces working with the wrapped model. If I were refactoring the code and not just getting rid of wrapping, I would probably just unwrap and rewrap at the API layer and allow the rest of the code to ignore the issue as much as possible.
Mark On Mon, Mar 27, 2017 at 5:49 AM, 'Rupert Smith' via Elm Discuss < [email protected]> wrote: > On Sunday, March 26, 2017 at 10:57:46 PM UTC+1, Mark Hamburg wrote: >> >> I think I have some code that follows this pattern: >> >> module Mod exposing (Model, Msg, update) >> >> type Model = Model Imp >> >> type alias Imp = { ... private stuff goes here ... } >> >> update : Msg -> Model -> ( Model, Cmd Msg ) >> update msg (Model imp) = >> updateImp msg imp |> rewrap >> >> rewrap : (Imp, x) -> (Model, x) >> rewrap (imp, x) = >> (Model imp, x) >> >> >> >> - A concern that this inhibits potential efficiency around cases >> where the update doesn't change the model but just results in additional >> commands >> >> Bear in mind that you don't have to unwrap/rewrap the model in this case. > The 'as' keyword lets you pattern match and keep the original at the same > time: > > update msg (Model imp as model) = > case msg of > ThisOneUpdatesImp -> updateImp msg imp |> rewrap > | ThisOneDoesnt -> (model, someCmd) > > -- > 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. > -- 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.
