Skip to content

Instantly share code, notes, and snippets.

@TheDahv
Last active September 23, 2016 16:05
Show Gist options
  • Save TheDahv/32d4cf984e58a707e9e079b408d21fe8 to your computer and use it in GitHub Desktop.
Save TheDahv/32d4cf984e58a707e9e079b408d21fe8 to your computer and use it in GitHub Desktop.
Figuring out how to model and walk recursive relationships in Elm
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