Implement tree functions
This commit is contained in:
parent
54ec7afa59
commit
3255bfd2ec
3 changed files with 140 additions and 28 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue