Last active
September 23, 2016 16:05
-
-
Save TheDahv/32d4cf984e58a707e9e079b408d21fe8 to your computer and use it in GitHub Desktop.
Figuring out how to model and walk recursive relationships in Elm
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
type alias Content = | |
{ title : String | |
, copy : String | |
, children : Children | |
} | |
type Children | |
= Children (List Content) | |
tableOfContents : List ( String, String ) -> Model -> Html Msg | |
tableOfContents parentStyles { document } = | |
let | |
renderHeading { title, children } = | |
li [] | |
[ text title | |
, ul [] (walkChildren children) | |
] | |
walkChildren (Children children) = | |
List.map renderHeading children | |
in | |
renderHeading document |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment