| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Cardano.Logging.DocuGenerator.Tree
Documentation
Non-empty, possibly infinite, multi-way trees; also known as rose trees.
Instances
| FromJSON1 Tree | |
Defined in Data.Aeson.Types.FromJSON Methods liftParseJSON :: Maybe a -> (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (Tree a) liftParseJSONList :: Maybe a -> (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [Tree a] liftOmittedField :: Maybe a -> Maybe (Tree a) | |
| ToJSON1 Tree | |
Defined in Data.Aeson.Types.ToJSON Methods liftToJSON :: (a -> Bool) -> (a -> Value) -> ([a] -> Value) -> Tree a -> Value liftToJSONList :: (a -> Bool) -> (a -> Value) -> ([a] -> Value) -> [Tree a] -> Value liftToEncoding :: (a -> Bool) -> (a -> Encoding) -> ([a] -> Encoding) -> Tree a -> Encoding liftToEncodingList :: (a -> Bool) -> (a -> Encoding) -> ([a] -> Encoding) -> [Tree a] -> Encoding liftOmitField :: (a -> Bool) -> Tree a -> Bool | |
| MonadFix Tree | Since: containers-0.5.11 |
| MonadZip Tree | |
| Foldable Tree | Folds in preorder |
Defined in Data.Tree Methods fold :: Monoid m => Tree m -> m Source # foldMap :: Monoid m => (a -> m) -> Tree a -> m Source # foldMap' :: Monoid m => (a -> m) -> Tree a -> m Source # foldr :: (a -> b -> b) -> b -> Tree a -> b Source # foldr' :: (a -> b -> b) -> b -> Tree a -> b Source # foldl :: (b -> a -> b) -> b -> Tree a -> b Source # foldl' :: (b -> a -> b) -> b -> Tree a -> b Source # foldr1 :: (a -> a -> a) -> Tree a -> a Source # foldl1 :: (a -> a -> a) -> Tree a -> a Source # toList :: Tree a -> [a] Source # null :: Tree a -> Bool Source # length :: Tree a -> Int Source # elem :: Eq a => a -> Tree a -> Bool Source # maximum :: Ord a => Tree a -> a Source # minimum :: Ord a => Tree a -> a Source # | |
| Foldable1 Tree | Folds in preorder Since: containers-0.6.7 |
Defined in Data.Tree Methods fold1 :: Semigroup m => Tree m -> m Source # foldMap1 :: Semigroup m => (a -> m) -> Tree a -> m Source # foldMap1' :: Semigroup m => (a -> m) -> Tree a -> m Source # toNonEmpty :: Tree a -> NonEmpty a Source # maximum :: Ord a => Tree a -> a Source # minimum :: Ord a => Tree a -> a Source # foldrMap1 :: (a -> b) -> (a -> b -> b) -> Tree a -> b Source # foldlMap1' :: (a -> b) -> (b -> a -> b) -> Tree a -> b Source # foldlMap1 :: (a -> b) -> (b -> a -> b) -> Tree a -> b Source # foldrMap1' :: (a -> b) -> (a -> b -> b) -> Tree a -> b Source # | |
| Eq1 Tree | Since: containers-0.5.9 |
| Ord1 Tree | Since: containers-0.5.9 |
| Read1 Tree | Since: containers-0.5.9 |
Defined in Data.Tree Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Tree a) Source # liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Tree a] Source # liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Tree a) Source # liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Tree a] Source # | |
| Show1 Tree | Since: containers-0.5.9 |
| Traversable Tree | |
| Applicative Tree | |
| Functor Tree | |
| Monad Tree | |
| Hashable1 Tree | |
Defined in Data.Hashable.Class | |
| Generic1 Tree | |
| Lift a => Lift (Tree a :: Type) | Since: containers-0.6.6 |
| FromJSON v => FromJSON (Tree v) | |
Defined in Data.Aeson.Types.FromJSON Methods parseJSON :: Value -> Parser (Tree v) parseJSONList :: Value -> Parser [Tree v] omittedField :: Maybe (Tree v) | |
| ToJSON v => ToJSON (Tree v) | |
Defined in Data.Aeson.Types.ToJSON Methods toEncoding :: Tree v -> Encoding toJSONList :: [Tree v] -> Value toEncodingList :: [Tree v] -> Encoding | |
| Data a => Data (Tree a) | |
Defined in Data.Tree Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Tree a -> c (Tree a) Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Tree a) Source # toConstr :: Tree a -> Constr Source # dataTypeOf :: Tree a -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Tree a)) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Tree a)) Source # gmapT :: (forall b. Data b => b -> b) -> Tree a -> Tree a Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tree a -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tree a -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Tree a -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Tree a -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Tree a -> m (Tree a) Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Tree a -> m (Tree a) Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Tree a -> m (Tree a) Source # | |
| Generic (Tree a) | |
| Read a => Read (Tree a) | |
| Show a => Show (Tree a) | |
| NFData a => NFData (Tree a) | |
| Eq a => Eq (Tree a) | |
| Ord a => Ord (Tree a) | Since: containers-0.6.5 |
| Hashable v => Hashable (Tree v) | |
Defined in Data.Hashable.Class | |
| Serialise a => Serialise (Tree a) | |
Defined in Codec.Serialise.Class | |
| type Rep1 Tree | Since: containers-0.5.8 |
Defined in Data.Tree type Rep1 Tree = D1 ('MetaData "Tree" "Data.Tree" "containers-0.6.7" 'False) (C1 ('MetaCons "Node" 'PrefixI 'True) (S1 ('MetaSel ('Just "rootLabel") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Just "subForest") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (List :.: Rec1 Tree))) | |
| type Rep (Tree a) | Since: containers-0.5.8 |
Defined in Data.Tree type Rep (Tree a) = D1 ('MetaData "Tree" "Data.Tree" "containers-0.6.7" 'False) (C1 ('MetaCons "Node" 'PrefixI 'True) (S1 ('MetaSel ('Just "rootLabel") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Just "subForest") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Tree a]))) | |
foldTree :: (a -> [b] -> b) -> Tree a -> b Source #
Fold a tree into a "summary" value in depth-first order.
For each node in the tree, apply f to the rootLabel and the result
of applying f to each subForest.
This is also known as the catamorphism on trees.
Examples
Sum the values in a tree:
foldTree (\x xs -> sum (x:xs)) (Node 1 [Node 2 [], Node 3 []]) == 6
Find the maximum value in the tree:
foldTree (\x xs -> maximum (x:xs)) (Node 1 [Node 2 [], Node 3 []]) == 3
Count the number of leaves in the tree:
foldTree (\_ xs -> if null xs then 1 else sum xs) (Node 1 [Node 2 [], Node 3 []]) == 2
Find depth of the tree; i.e. the number of branches from the root of the tree to the furthest leaf:
foldTree (\_ xs -> if null xs then 0 else 1 + maximum xs) (Node 1 [Node 2 [], Node 3 []]) == 1
You can even implement traverse using foldTree:
traverse' f = foldTree (\x xs -> liftA2 Node (f x) (sequenceA xs))
Since: containers-0.5.8