Add tree structure generation
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
{-|
|
||||
Combining and composing trees with 'Either' nodes.
|
||||
-}
|
||||
module Dodge.Layout.Tree.Either
|
||||
( expandTreeBy
|
||||
) where
|
||||
import Data.Tree
|
||||
|
||||
-- | 'Left' elements get new children as given by the node function,
|
||||
-- 'Right' elements inherit the children from the base tree
|
||||
expandTreeBy
|
||||
:: (a -> Tree (Either b b)) -- ^ Node function
|
||||
-> Tree a -- ^ Base tree
|
||||
-> Tree b
|
||||
expandTreeBy f (Node x []) = fmap removeEither (f x)
|
||||
expandTreeBy f (Node x xs) = appendAndRemove $ f x
|
||||
where
|
||||
appendAndRemove (Node (Left y) ys) = Node y (map appendAndRemove ys)
|
||||
appendAndRemove (Node (Right y) _ ) = Node y (map (expandTreeBy f) xs)
|
||||
|
||||
removeEither (Left y) = y
|
||||
removeEither (Right y) = y
|
||||
Reference in New Issue
Block a user