Last active
July 23, 2017 15:46
-
-
Save jbrains/01625b04de92cfc96e4f0e08485d066c to your computer and use it in GitHub Desktop.
Removing duplication with Elm record syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
playerDetailsViewModel : (PlayerId -> Int) -> PlayerModel -> PlayerDetailsViewModel | |
playerDetailsViewModel playerPointsScored playerModel = | |
PlayerDetailsViewModel | |
playerModel.id | |
playerModel.name | |
(playerPointsScored playerModel.id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
playerDetailsViewModel : (PlayerId -> Int) -> PlayerModel -> PlayerDetailsViewModel | |
playerDetailsViewModel playerPointsScored { id, name } = | |
PlayerDetailsViewModel | |
id | |
name | |
(playerPointsScored id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
From my expereience in both OOP but even stronger from my experience in FP: it is not a good idea to flatten data. Yes you should not let the called function or method go deep into your structure and do what it want either. Instead you should use functors and or other pattern to embellish the methods and functions so that they don't need to know about the wrapping structures.
It would be interesting to see the usage of the view-model. Right now it seams like it would be better of just being a pair (or any product type).
or something like that. I wish to make getScore dot free but i dont know elm good enough for that. Now the renderer dont need to know how to render a pair just how to render models and scores and you can use mapBoth to get both outputs and combine them later.