Add distinction between an empty node and a leaf to allow truncating the output right after a node
This commit is contained in:
parent
ed5ee22a49
commit
2780b38df2
2 changed files with 4 additions and 2 deletions
|
@ -16,6 +16,7 @@ instance Functor Stream where
|
|||
Stream $ (\(a, stream) -> (f a, fmap f stream)) <$> pairs
|
||||
|
||||
instance Tree Stream where
|
||||
getStructure (Stream []) = Leaf
|
||||
getStructure (Stream pairs) =
|
||||
Node $ (\(s, stream) -> (s, getStructure stream)) <$> pairs
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ module Tree (
|
|||
, Structure(..)
|
||||
) where
|
||||
|
||||
data Structure = Node [(String, Structure)]
|
||||
data Structure = Leaf | Node [(String, Structure)]
|
||||
|
||||
class Functor a => Tree a where
|
||||
getStructure :: a String -> Structure
|
||||
|
@ -12,7 +12,8 @@ class Functor a => Tree a where
|
|||
draw = unlines . getLines . getStructure . fmap show
|
||||
|
||||
getLines :: Structure -> [String]
|
||||
getLines (Node []) = ["╼"]
|
||||
getLines Leaf = ["╼"]
|
||||
getLines (Node []) = [""]
|
||||
getLines (Node [(s, structure)]) = showBlock '─' (s, structure)
|
||||
getLines (Node ((s, structure):pairs)) = concat $
|
||||
showBlock '┬' (s, structure) : showBlocks pairs
|
||||
|
|
Loading…
Reference in a new issue