Skip to content

Commit

Permalink
Merge pull request ekmett#110 from chowells79/doc-2015-10-17
Browse files Browse the repository at this point in the history
Cleanups to Control.Comonad.Cofree.telescoped
  • Loading branch information
ekmett committed Oct 19, 2015
2 parents f12846a + d16335a commit a917e3c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Control/Comonad/Cofree.hs
Original file line number Diff line number Diff line change
Expand Up @@ -344,12 +344,24 @@ _unwrap :: Functor f => (g (Cofree g a) -> f (g (Cofree g a))) -> Cofree g a ->
_unwrap f (a :< as) = (a :<) <$> f as
{-# INLINE _unwrap #-}

-- | Construct a @Lens@ into a @'Cofree' f@ given a list of lenses into the base functor.
-- | Construct an @Lens@ into a @'Cofree' g@ given a list of lenses into the base functor.
-- When the input list is empty, this is equivalent to '_extract'.
-- When the input list is non-empty, this composes the input lenses
-- with '_unwrap' to walk through the @'Cofree' g@ before using
-- '_extract' to get the element at the final location.
--
-- For more on lenses see the 'lens' package on hackage.
--
-- @telescoped :: 'Functor' g => [Lens' ('Cofree' g a) (g ('Cofree' g a))] -> Lens' ('Cofree' g a) a@
telescoped :: (Functor f, Functor g) =>
-- @telescoped :: [Lens' (g ('Cofree' g a)) ('Cofree' g a)] -> Lens' ('Cofree' g a) a@
--
-- @telescoped :: [Traversal' (g ('Cofree' g a)) ('Cofree' g a)] -> Traversal' ('Cofree' g a) a@
--
-- @telescoped :: [Getter (g ('Cofree' g a)) ('Cofree' g a)] -> Getter ('Cofree' g a) a@
--
-- @telescoped :: [Fold (g ('Cofree' g a)) ('Cofree' g a)] -> Fold ('Cofree' g a) a@
--
-- @telescoped :: [Setter' (g ('Cofree' g a)) ('Cofree' g a)] -> Setter' ('Cofree' g a) a@
telescoped :: Functor f =>
[(Cofree g a -> f (Cofree g a)) -> g (Cofree g a) -> f (g (Cofree g a))] ->
(a -> f a) -> Cofree g a -> f (Cofree g a)
telescoped = Prelude.foldr (\l r -> _unwrap . l . r) _extract
Expand Down

0 comments on commit a917e3c

Please sign in to comment.