-- | Tree functions
module Music.Theory.Tree where

import qualified Data.Tree as Tree {- containers -}

-- | Print forest as markdown list.
mdForest :: Tree.Forest String -> String
mdForest :: Forest String -> String
mdForest  = [String] -> String
unlines forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Int -> Tree String -> [String]
mdTree Int
0)

-- | Print tree as markdown list with indicated starting indent level.
mdTree :: Int -> Tree.Tree String -> [String]
mdTree :: Int -> Tree String -> [String]
mdTree Int
k (Tree.Node String
txt Forest String
st) = (forall a. Int -> a -> [a]
replicate (Int
k forall a. Num a => a -> a -> a
* Int
2) Char
' ' forall a. [a] -> [a] -> [a]
++ String
"- " forall a. [a] -> [a] -> [a]
++ String
txt) forall a. a -> [a] -> [a]
: forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (Int -> Tree String -> [String]
mdTree (Int
k forall a. Num a => a -> a -> a
+ Int
1)) Forest String
st