{-# LANGUAGE FlexibleContexts #-}
module Data.Tree.Lens
( root
, branches
) where
import Control.Lens
import Data.Functor
import Data.Tree
root :: Lens' (Tree a) a
root f (Node a as) = (`Node` as) <$> f a
{-# INLINE root #-}
branches :: Lens' (Tree a) [Tree a]
branches f (Node a as) = Node a <$> f as
{-# INLINE branches #-}