Permalink
Browse files

Doctests for magnify.

Signed-off-by: Austin Seipp <mad.one@gmail.com>
  • Loading branch information...
1 parent 6d87195 commit 4f321eeaf27006d008591ad927ce06535496e034 @thoughtpolice thoughtpolice committed Jan 7, 2013
Showing with 11 additions and 2 deletions.
  1. +11 −2 src/Control/Lens/Zoom.hs
@@ -31,15 +31,14 @@ import Control.Lens.Internal
import Control.Lens.Internal.Combinators
import Control.Lens.Type
import Control.Monad
-import Control.Monad.Reader.Class as Reader
+import Control.Monad.Reader as Reader
import Control.Monad.State as State
import Control.Monad.Trans.State.Lazy as Lazy
import Control.Monad.Trans.State.Strict as Strict
import Control.Monad.Trans.Writer.Lazy as Lazy
import Control.Monad.Trans.Writer.Strict as Strict
import Control.Monad.Trans.RWS.Lazy as Lazy
import Control.Monad.Trans.RWS.Strict as Strict
-import Control.Monad.Trans.Reader
import Control.Monad.Trans.Error
import Control.Monad.Trans.List
import Control.Monad.Trans.Identity
@@ -48,6 +47,7 @@ import Data.Monoid
-- $setup
-- >>> import Control.Lens
+-- >>> import Data.List.Lens (_tail)
-- >>> import Control.Monad.State
-- >>> import Data.Map as Map
-- >>> import Debug.SimpleReflect.Expr as Expr
@@ -160,6 +160,15 @@ class (MonadReader b m, MonadReader a n) => Magnify m n k b a | m -> b k, n -> a
--
-- This can be used to edit pretty much any monad transformer stack with an environment in it:
--
+ -- >>> (1,2) & magnify _2 (+1)
+ -- 3
+ --
+ -- >>> flip Reader.runReader (1,2) $ magnify _1 Reader.ask
+ -- 1
+ --
+ -- >>> flip Reader.runReader (1,2,[10..20]) $ magnify (_3._tail) Reader.ask
+ -- [11,12,13,14,15,16,17,18,19,20]
+ --
-- @
-- 'magnify' :: 'Getter' s a -> (a -> r) -> s -> r
-- 'magnify' :: 'Monoid' c => 'Fold' s a -> (a -> r) -> s -> r

0 comments on commit 4f321ee

Please sign in to comment.