On Tuesday, March 28, 2017 at 3:31:34 AM UTC+1, Mark Hamburg wrote: > > 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. >
Yes, I think that is a nice clean approach. You could also group your API functions together in one place: module FunkyDoDa exposing (computeIt) -- API computeIt : Model -> Model computeIt (Wrapped impl) = computeItImpl impl |> Impl -- Implementation computeItImpl : Impl -> Impl ... As all the API functions would be simple wrap/unwrap boiler plate, they would all be short. Put near the top of the file and then it is easy to scan the API and its type signatures. The only module I have where I have written other modules that depend on what is inside the Model is my Auth module - other modules look up what the logged on state it, what the current username is etc. I added some features to it recently, and now it occurs to me that I would be better making its model opaque and supplying functions to extract the things other modules need to know, then I can refactor its model internally along the make-impossible-states-unrepresentable line and all the dependant modules will continue to work correctly. -- 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.
