
I was thinking of:
length :: Tree a -> Int
length = L.length . flatten
But to be honest, I don't have strong feelings about this, I'm willing to
drop this particular function (length) from the proposal, if there is no
consensus.
João
2014-02-24 10:50 GMT+00:00 Ivan Lazar Miljenovic
On 24 February 2014 21:39, João Cristóvão
wrote: Hello,
The Data.Tree API seems rather poor. Some research on hackage shows some additional functions being defined in very unrelated packages:
http://hackage.haskell.org/package/debian-3.81/docs/Debian-Apt-Dependencies....
http://hackage.haskell.org/package/hledger-lib-0.22.1/docs/Hledger-Utils.htm...
I propose the addition of the following functions, that seem rather
forward to me:
-- | get the sub-tree rooted at the first (left-most, depth-first) occurrence -- of the specified node value lookupTree :: Eq a => a -> Tree a -> Maybe (Tree a)
-- | get the sub-tree rooted at the first (left-most, depth-first) value that -- matches the provided condition findTree :: (a -> Bool) -> Tree a -> Maybe (Tree a)
-- | keep only the elements that match the provided condition filter :: (a -> Bool) -> Tree a -> Tree a
The 'Tree' is appended in the name, to distinguish from the Foldable instances, that return the value, and not a sub-tree.
Additionally, the following two functions might also be useful (even if
straigh the
implementation is very simple in the second case): -- | get the sub-tree for the specified node value in the first tree in -- forest in which it occurs. lookupTreeInForest :: Eq a => a -> [Tree a] -> Maybe (Tree a)
-- | Length of the tree length :: Tree a -> Int
What is the length of a tree? The number of sub-trees of that particular root node? The overall width of the tree? The number of nodes?
There are probably more useful functions to add, so suggestions are welcomed.
Previous discussion: https://github.com/haskell/containers/issues/39#issuecomment-35799628
Discussion period: 2 weeks
Cheers, João
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
-- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com