polytree 0.0.6 → 0.0.7
raw patch · 3 files changed
+41/−6 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.PolyTree: traverseNode :: forall (f :: Type -> Type) a b a'. Traversable f => Traversal (Tree f a b) (Tree f a' b) (a, f (Tree f a b)) a'
+ Data.PolyTree: traverseNode_ :: forall (f :: Type -> Type) a b a'. Foldable f => Traversal (Tree f a b) () (a, f (Tree f a b)) a'
Files
- changelog.md +5/−0
- polytree.cabal +1/−1
- src/Data/PolyTree.hs +35/−5
changelog.md view
@@ -1,3 +1,8 @@+0.0.7++* Fix `Show` instance+* Add `traverseNode` and `traverseNode_`+ 0.0.6 * Add `foldTreeM_`
polytree.cabal view
@@ -1,5 +1,5 @@ name: polytree-version: 0.0.6+version: 0.0.7 synopsis: A polymorphic rose-tree description: A rose-tree which has different data in the nodes and leaves license: BSD3
src/Data/PolyTree.hs view
@@ -27,6 +27,7 @@ import Data.Bifoldable ( Bifoldable(bifoldMap) ) import Data.Bifunctor ( Bifunctor(bimap) ) import Data.Bitraversable ( Bitraversable(..) )+import Data.Foldable import Data.Functor ( void ) import Data.Functor.Apply ( Apply((<.>)) ) import Data.Functor.Bind ( Bind((>>-)) )@@ -117,8 +118,8 @@ liftCompare compare instance (Show a, Show1 f, Show b) => Show (Tree f a b) where- show x =- liftShowsPrec showsPrec shows 0 x ""+ showsPrec =+ liftShowsPrec showsPrec shows -- | --@@ -360,7 +361,7 @@ -- | -- -- >>> toListOf plate (Leaf 1 :: Tree0' Int)--- []+-- [Leaf 1] -- -- >>> toListOf plate (Node 1 [] :: Tree0' Int) -- []@@ -374,8 +375,8 @@ -- >>> toListOf plate (Node 1 [Leaf 2, Leaf 3, Node 4 [Leaf 5]] :: Tree0' Int) -- [Leaf 2,Leaf 3,Node 4 [Leaf 5]] instance Traversable f => Plated (Tree f a b) where- plate _ (Leaf b) =- pure (Leaf b)+ plate f (Leaf b) =+ f (Leaf b) plate f (Node a ts) = Node a <$> traverse f ts @@ -684,6 +685,35 @@ -> Tree1 a b node1 a t = review _Node1 (a, t)++-- |+--+-- >>> traverseNode (\(a, t) -> [(a, t)]) (Leaf 1 :: Tree0' Int)+-- [Leaf 1]+--+-- >>> traverseNode (\(a, t) -> [(a, t)]) (Node 1 [] :: Tree0' Int)+-- [Node (1,[]) []]+--+-- >>> traverseNode (\(a, t) -> [(a, t)]) (Node 1 [Leaf 2] :: Tree0' Int)+-- [Node (1,[Leaf 2]) [Leaf 2]]+--+-- >>> traverseNode (\(a, t) -> [(a, t)]) (Node 1 [Leaf 2, Node 3 []] :: Tree0' Int)+-- [Node (1,[Leaf 2,Node 3 []]) [Leaf 2,Node (3,[]) []]]+traverseNode ::+ Traversable f =>+ Traversal (Tree f a b) (Tree f a' b) (a, f (Tree f a b)) a'+traverseNode _ (Leaf b) =+ pure (Leaf b)+traverseNode f (Node a t) =+ Node <$> f (a, t) <*> traverse (traverseNode f) t++traverseNode_ ::+ Foldable f =>+ Traversal (Tree f a b) () (a, f (Tree f a b)) a'+traverseNode_ f (Leaf b) =+ void (pure (Leaf b))+traverseNode_ f (Node a t) =+ f (a, t) *> traverse_ (traverseNode_ f) t -- | --