hedgehog-1.5: Release with confidence.

Safe Haskell | None
Language | Haskell2010

Hedgehog.Internal.Tree

Synopsis

- type Tree = TreeT Identity
- pattern Tree :: NodeT Identity a -> Tree a
- newtype TreeT (m :: Type -> Type) a = TreeT {
  - runTreeT :: m (NodeT m a)
  }
- runTree :: Tree a -> Node a
- mapTreeT :: (m (NodeT m a) -> m (NodeT m a)) -> TreeT m a -> TreeT m a
- treeValue :: Tree a -> a
- treeChildren :: Tree a -> [Tree a]
- type Node = NodeT Identity
- pattern Node :: a -> [Tree a] -> Node a
- data NodeT (m :: Type -> Type) a = NodeT {
  - nodeValue :: a
  - nodeChildren :: [TreeT m a]
  }
- fromNodeT :: forall (m :: Type -> Type) a. Applicative m => NodeT m a -> TreeT m a
- unfold :: forall (m :: Type -> Type) a. Monad m => (a -> [a]) -> a -> TreeT m a
- unfoldForest :: forall (m :: Type -> Type) a. Monad m => (a -> [a]) -> a -> [TreeT m a]
- expand :: forall (m :: Type -> Type) a. Monad m => (a -> [a]) -> TreeT m a -> TreeT m a
- prune :: forall (m :: Type -> Type) a. Monad m => Int -> TreeT m a -> TreeT m a
- catMaybes :: Tree (Maybe a) -> Maybe (Tree a)
- filter :: (a -> Bool) -> Tree a -> Maybe (Tree a)
- mapMaybe :: (a -> Maybe b) -> Tree a -> Maybe (Tree b)
- filterMaybeT :: (a -> Bool) -> TreeT (MaybeT Identity) a -> TreeT (MaybeT Identity) a
- mapMaybeMaybeT :: (a -> Maybe b) -> TreeT (MaybeT Identity) a -> TreeT (MaybeT Identity) b
- filterT :: forall (m :: Type -> Type) a. (Monad m, Alternative m) => (a -> Bool) -> TreeT m a -> TreeT m a
- consChild :: forall (m :: Type -> Type) a. Monad m => a -> TreeT m a -> TreeT m a
- mapMaybeT :: forall (m :: Type -> Type) a b. (Monad m, Alternative m) => (a -> Maybe b) -> TreeT m a -> TreeT m b
- depth :: Tree a -> Int
- interleave :: forall (m :: Type -> Type) a. Monad m => [NodeT m a] -> NodeT m [a]
- render :: Tree String -> String
- renderT :: Monad m => TreeT m String -> m String

# Documentation

type Tree = TreeT Identity Source #

A rose tree.

pattern Tree :: NodeT Identity a -> Tree a Source #

Pattern to ease construction / deconstruction of pure trees.

newtype TreeT (m :: Type -> Type) a Source #

An effectful tree, each node in the tree can have an effect before it is produced.

Constructors

TreeT |

Fields

- runTreeT :: m (NodeT m a)

#### Instances

Instances details

Foldable Tree Source # |

Instance details

Defined in Hedgehog.Internal.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 #

sum :: Num a => Tree a -> a Source #

product :: Num a => Tree a -> a Source #

Traversable Tree Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods traverse :: Applicative f => (a -> f b) -> Tree a -> f (Tree b) Source # sequenceA :: Applicative f => Tree (f a) -> f (Tree a) Source # mapM :: Monad m => (a -> m b) -> Tree a -> m (Tree b) Source # sequence :: Monad m => Tree (m a) -> m (Tree a) Source #
MonadTransDistributive TreeT Source # |

Instance details

Defined in Hedgehog.Internal.Tree

Associated Types

type Transformer f TreeT m |
Instance details Defined in Hedgehog.Internal.Tree type Transformer f TreeT m = (Monad m, Monad (f m), Monad (TreeT m), Monad (f (TreeT m)), MonadTrans f, MFunctor f)

Methods

distributeT :: forall f (m :: Type -> Type) a. Transformer f TreeT m => TreeT (f m) a -> f (TreeT m) a Source #

MMonad TreeT Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods embed :: forall (n :: Type -> Type) m b. Monad n => (forall a. m a -> TreeT n a) -> TreeT m b -> TreeT n b Source #
MonadTrans TreeT Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods lift :: Monad m => m a -> TreeT m a Source #
MFunctor TreeT Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods hoist :: Monad m => (forall a. m a -> n a) -> TreeT m b -> TreeT n b Source #
MonadBaseControl b m => MonadBaseControl b (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods liftBaseWith :: (RunInBase (TreeT m) b -> b a) -> TreeT m a Source # restoreM :: StM (TreeT m) a -> TreeT m a Source #
MonadError e m => MonadError e (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods throwError :: e -> TreeT m a Source # catchError :: TreeT m a -> (e -> TreeT m a) -> TreeT m a Source #
MonadReader r m => MonadReader r (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods ask :: TreeT m r Source # local :: (r -> r) -> TreeT m a -> TreeT m a Source # reader :: (r -> a) -> TreeT m a Source #
MonadState s m => MonadState s (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods get :: TreeT m s Source # put :: s -> TreeT m () Source # state :: (s -> (a, s)) -> TreeT m a Source #
MonadWriter w m => MonadWriter w (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods writer :: (a, w) -> TreeT m a Source # tell :: w -> TreeT m () Source # listen :: TreeT m a -> TreeT m (a, w) Source # pass :: TreeT m (a, w -> w) -> TreeT m a Source #
MonadBase b m => MonadBase b (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods liftBase :: b α -> TreeT m α Source #
MonadIO m => MonadIO (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods liftIO :: IO a -> TreeT m a Source #
Monad m => MonadZip (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods mzip :: TreeT m a -> TreeT m b -> TreeT m (a, b) Source # mzipWith :: (a -> b -> c) -> TreeT m a -> TreeT m b -> TreeT m c Source # munzip :: TreeT m (a, b) -> (TreeT m a, TreeT m b) Source #
Show1 m => Show1 (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> TreeT m a -> ShowS Source # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [TreeT m a] -> ShowS Source #
MonadCatch m => MonadCatch (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods catch :: (HasCallStack, Exception e) => TreeT m a -> (e -> TreeT m a) -> TreeT m a Source #
MonadThrow m => MonadThrow (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods throwM :: (HasCallStack, Exception e) => e -> TreeT m a Source #
Alternative m => Alternative (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods empty :: TreeT m a Source # (<|>) :: TreeT m a -> TreeT m a -> TreeT m a Source # some :: TreeT m a -> TreeT m [a] Source # many :: TreeT m a -> TreeT m [a] Source #
Applicative m => Applicative (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods pure :: a -> TreeT m a Source # (<*>) :: TreeT m (a -> b) -> TreeT m a -> TreeT m b Source # liftA2 :: (a -> b -> c) -> TreeT m a -> TreeT m b -> TreeT m c Source # (*>) :: TreeT m a -> TreeT m b -> TreeT m b Source # (<*) :: TreeT m a -> TreeT m b -> TreeT m a Source #
Functor m => Functor (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods fmap :: (a -> b) -> TreeT m a -> TreeT m b Source # (<$) :: a -> TreeT m b -> TreeT m a Source #
Monad m => Monad (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods (>>=) :: TreeT m a -> (a -> TreeT m b) -> TreeT m b Source # (>>) :: TreeT m a -> TreeT m b -> TreeT m b Source # return :: a -> TreeT m a Source #
MonadPlus m => MonadPlus (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods mzero :: TreeT m a Source # mplus :: TreeT m a -> TreeT m a -> TreeT m a Source #
PrimMonad m => PrimMonad (TreeT m) Source # |

Instance details

Defined in Hedgehog.Internal.Tree

Associated Types

type PrimState (TreeT m) |
Instance details Defined in Hedgehog.Internal.Tree type PrimState (TreeT m) = PrimState m

Methods

primitive :: (State# (PrimState (TreeT m)) -> (# State# (PrimState (TreeT m)), a #)) -> TreeT m a Source #

MonadResource m => MonadResource (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods liftResourceT :: ResourceT IO a -> TreeT m a Source #
(Show1 m, Show a) => Show (TreeT m a) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods showsPrec :: Int -> TreeT m a -> ShowS Source # show :: TreeT m a -> String Source # showList :: [TreeT m a] -> ShowS Source #
(Eq1 m, Eq a) => Eq (TreeT m a) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods (==) :: TreeT m a -> TreeT m a -> Bool Source # (/=) :: TreeT m a -> TreeT m a -> Bool Source #
type Transformer f TreeT m Source # |
Instance details Defined in Hedgehog.Internal.Tree type Transformer f TreeT m = (Monad m, Monad (f m), Monad (TreeT m), Monad (f (TreeT m)), MonadTrans f, MFunctor f)
type PrimState (TreeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree type PrimState (TreeT m) = PrimState m
type StM (TreeT m) a Source # |
Instance details Defined in Hedgehog.Internal.Tree type StM (TreeT m) a = StM m (NodeT m a)

runTree :: Tree a -> Node a Source #

Extracts the `Node` from a `Tree`.

mapTreeT :: (m (NodeT m a) -> m (NodeT m a)) -> TreeT m a -> TreeT m a Source #

Map between `TreeT` computations.

treeValue :: Tree a -> a Source #

The value at the root of the `Tree`.

treeChildren :: Tree a -> [Tree a] Source #

The children of the `Tree`.

type Node = NodeT Identity Source #

A node in a rose tree.

pattern Node :: a -> [Tree a] -> Node a Source #

Pattern to ease construction / deconstruction of pure nodes.

data NodeT (m :: Type -> Type) a Source #

A node in an effectful tree, as well as its unevaluated children.

Constructors

NodeT |

Fields

- nodeValue :: a

  The value at this `NodeT` in the `TreeT`.

- nodeChildren :: [TreeT m a]

  The children of this `NodeT`.

#### Instances

Instances details

Foldable Node Source # |

Instance details

Defined in Hedgehog.Internal.Tree

Methods

fold :: Monoid m => Node m -> m Source #

foldMap :: Monoid m => (a -> m) -> Node a -> m Source #

foldMap' :: Monoid m => (a -> m) -> Node a -> m Source #

foldr :: (a -> b -> b) -> b -> Node a -> b Source #

foldr' :: (a -> b -> b) -> b -> Node a -> b Source #

foldl :: (b -> a -> b) -> b -> Node a -> b Source #

foldl' :: (b -> a -> b) -> b -> Node a -> b Source #

foldr1 :: (a -> a -> a) -> Node a -> a Source #

foldl1 :: (a -> a -> a) -> Node a -> a Source #

toList :: Node a -> [a] Source #

null :: Node a -> Bool Source #

length :: Node a -> Int Source #

elem :: Eq a => a -> Node a -> Bool Source #

maximum :: Ord a => Node a -> a Source #

minimum :: Ord a => Node a -> a Source #

sum :: Num a => Node a -> a Source #

product :: Num a => Node a -> a Source #

Traversable Node Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods traverse :: Applicative f => (a -> f b) -> Node a -> f (Node b) Source # sequenceA :: Applicative f => Node (f a) -> f (Node a) Source # mapM :: Monad m => (a -> m b) -> Node a -> m (Node b) Source # sequence :: Monad m => Node (m a) -> m (Node a) Source #
MFunctor NodeT Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods hoist :: Monad m => (forall a. m a -> n a) -> NodeT m b -> NodeT n b Source #
Show1 m => Show1 (NodeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> NodeT m a -> ShowS Source # liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [NodeT m a] -> ShowS Source #
Applicative m => Applicative (NodeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods pure :: a -> NodeT m a Source # (<*>) :: NodeT m (a -> b) -> NodeT m a -> NodeT m b Source # liftA2 :: (a -> b -> c) -> NodeT m a -> NodeT m b -> NodeT m c Source # (*>) :: NodeT m a -> NodeT m b -> NodeT m b Source # (<*) :: NodeT m a -> NodeT m b -> NodeT m a Source #
Functor m => Functor (NodeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods fmap :: (a -> b) -> NodeT m a -> NodeT m b Source # (<$) :: a -> NodeT m b -> NodeT m a Source #
Monad m => Monad (NodeT m) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods (>>=) :: NodeT m a -> (a -> NodeT m b) -> NodeT m b Source # (>>) :: NodeT m a -> NodeT m b -> NodeT m b Source # return :: a -> NodeT m a Source #
(Show1 m, Show a) => Show (NodeT m a) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods showsPrec :: Int -> NodeT m a -> ShowS Source # show :: NodeT m a -> String Source # showList :: [NodeT m a] -> ShowS Source #
(Eq a, Eq1 m) => Eq (NodeT m a) Source # |
Instance details Defined in Hedgehog.Internal.Tree Methods (==) :: NodeT m a -> NodeT m a -> Bool Source # (/=) :: NodeT m a -> NodeT m a -> Bool Source #

fromNodeT :: forall (m :: Type -> Type) a. Applicative m => NodeT m a -> TreeT m a Source #

Create a `TreeT` from a `NodeT`

unfold :: forall (m :: Type -> Type) a. Monad m => (a -> [a]) -> a -> TreeT m a Source #

Create a tree from a value and an unfolding function.

unfoldForest :: forall (m :: Type -> Type) a. Monad m => (a -> [a]) -> a -> [TreeT m a] Source #

Create a forest from a value and an unfolding function.

expand :: forall (m :: Type -> Type) a. Monad m => (a -> [a]) -> TreeT m a -> TreeT m a Source #

Expand a tree using an unfolding function.

prune :: forall (m :: Type -> Type) a. Monad m => Int -> TreeT m a -> TreeT m a Source #

Throw away all but the top `n` levels of a tree's children.

`prune 0` will throw away all of a tree's children.

catMaybes :: Tree (Maybe a) -> Maybe (Tree a) Source #

Takes a tree of `Maybe`s and returns a tree of all the `Just` values.

If the root of the tree is `Nothing` then `Nothing` is returned.

filter :: (a -> Bool) -> Tree a -> Maybe (Tree a) Source #

Returns a tree containing only elements that match the predicate.

If the root of the tree does not match the predicate then `Nothing` is returned.

mapMaybe :: (a -> Maybe b) -> Tree a -> Maybe (Tree b) Source #

filterMaybeT :: (a -> Bool) -> TreeT (MaybeT Identity) a -> TreeT (MaybeT Identity) a Source #

Returns a tree containing only elements that match the predicate.

If the root of the tree does not match the predicate then `Nothing` is returned.

mapMaybeMaybeT :: (a -> Maybe b) -> TreeT (MaybeT Identity) a -> TreeT (MaybeT Identity) b Source #

filterT :: forall (m :: Type -> Type) a. (Monad m, Alternative m) => (a -> Bool) -> TreeT m a -> TreeT m a Source #

Returns a tree containing only elements that match the predicate.

When an element does not match the predicate its node is replaced with `empty`.

consChild :: forall (m :: Type -> Type) a. Monad m => a -> TreeT m a -> TreeT m a Source #

mapMaybeT :: forall (m :: Type -> Type) a b. (Monad m, Alternative m) => (a -> Maybe b) -> TreeT m a -> TreeT m b Source #

depth :: Tree a -> Int Source #

Returns the depth of the deepest leaf node in the tree.

interleave :: forall (m :: Type -> Type) a. Monad m => [NodeT m a] -> NodeT m [a] Source #

render :: Tree String -> String Source #

Render a tree of strings.

renderT :: Monad m => TreeT m String -> m String Source #

Render a tree of strings, note that this forces all the delayed effects in the tree.