elm-community / graph

Functional Graph Library in Elm.

Home Page:http://package.elm-lang.org/packages/elm-community/graph/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implement map function for Tree

jhrcek opened this issue · comments

It would be nice if there was a map function with signature map : (a -> b) -> Tree a -> Tree b in the module Graph.Tree. I can create a PR for that if you agree.

Expected implementation would be

map : (a -> b) -> Tree a -> Tree b
map f (MkTree totalSize maybeLabelAndChildren) =
    MkTree totalSize <|
        Maybe.map
            (\( label, children ) -> ( f label, List.map (map f) children ))
            maybeLabelAndChildren

Closing as the PR implementing this was merged. Thank you.