polytree 0.0.7 → 0.0.8
raw patch · 3 files changed
+34/−5 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Data.PolyTree: leaves :: (Traversable f, Alternative f) => Tree f a b -> f b
Files
- changelog.md +5/−1
- polytree.cabal +1/−1
- src/Data/PolyTree.hs +28/−3
changelog.md view
@@ -1,7 +1,11 @@+0.0.8++* Add `leaves` function+ 0.0.7 * Fix `Show` instance-* Add `traverseNode` and `traverseNode_`+* Add `traverseNode` and `traverseNode_` functions 0.0.6
polytree.cabal view
@@ -1,5 +1,5 @@ name: polytree-version: 0.0.7+version: 0.0.8 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
@@ -4,7 +4,7 @@ module Data.PolyTree where -import Control.Applicative ( Applicative(liftA2), Alternative(empty) )+import Control.Applicative ( Applicative(liftA2), Alternative(empty), asum ) import Control.Lens ( preview, iso,@@ -27,7 +27,7 @@ import Data.Bifoldable ( Bifoldable(bifoldMap) ) import Data.Bifunctor ( Bifunctor(bimap) ) import Data.Bitraversable ( Bitraversable(..) )-import Data.Foldable+import Data.Foldable ( traverse_ ) import Data.Functor ( void ) import Data.Functor.Apply ( Apply((<.>)) ) import Data.Functor.Bind ( Bind((>>-)) )@@ -710,7 +710,7 @@ traverseNode_ :: Foldable f => Traversal (Tree f a b) () (a, f (Tree f a b)) a'-traverseNode_ f (Leaf b) =+traverseNode_ _ (Leaf b) = void (pure (Leaf b)) traverseNode_ f (Node a t) = f (a, t) *> traverse_ (traverseNode_ f) t@@ -738,6 +738,31 @@ iso (matchTree (, Nothing) (\a t -> (a, Just t))) (\(a, t) -> maybe (Leaf a) (Node a) t)++-- |+--+-- >>> leaves (Leaf 1 :: Tree0' Int)+-- [1]+--+-- >>> leaves (Node 1 [] :: Tree0' Int)+-- []+--+-- >>> leaves (Node 1 [Leaf 2] :: Tree0' Int)+-- [2]+--+-- >>> leaves (Node 1 [Leaf 2, Node 3 []] :: Tree0' Int)+-- [2]+--+-- >>> leaves (Node 1 [Leaf 2, Node 3 [Leaf 4]] :: Tree0' Int)+-- [2,4]+leaves ::+ (Traversable f, Alternative f) =>+ Tree f a b+ -> f b+leaves (Leaf b) =+ pure b+leaves (Node _ t) =+ asum (fmap leaves t) -- | --