Implement tree functions

This commit is contained in:
Joscha 2020-02-09 11:29:19 +00:00
parent 54ec7afa59
commit 3255bfd2ec
3 changed files with 140 additions and 28 deletions

View file

@ -11,6 +11,7 @@ module Forest.Node
, initialNode
, applyId
, applyPath
, mapChildren
-- * Path
, Path(..)
, localPath
@ -66,6 +67,9 @@ applyId nodeId node = nodeChildren node Map.!? nodeId
applyPath :: Path -> Node -> Maybe Node
applyPath (Path ids) node = foldM (flip applyId) node ids
mapChildren :: (NodeId -> Node -> a) -> Node -> [a]
mapChildren f node = map (uncurry f) $ Map.toAscList $ nodeChildren node
{- Path -}
newtype Path = Path