# ekmett/lens

Use Haddock's syntax for interactive examples

1 parent bc60979 commit 7e4c554e75a9e2d6c1186313fa5418276bed8665 sol committed Aug 5, 2012
Showing with 28 additions and 28 deletions.
1. +14 −14 src/Control/Lens.hs
2. +2 −2 src/Data/IntMap/Lens.hs
3. +2 −2 src/Data/IntSet/Lens.hs
4. +6 −6 src/Data/List/Lens.hs
5. +2 −2 src/Data/Map/Lens.hs
6. +2 −2 src/Data/Set/Lens.hs
 @@ -508,8 +508,8 @@ sequenceOf l = unwrapMonad . l WrapMonad -- -- > transpose = transposeOf traverse -- --- > ghci> transposeOf traverse [[1,2,3],[4,5,6]] --- > [[1,4],[2,5],[3,6]] +-- >>> transposeOf traverse [[1,2,3],[4,5,6]] +-- [[1,4],[2,5],[3,6]] -- -- Since every 'Lens' is a Traversal, we can use this as a form of -- monadic strength. @@ -688,8 +688,8 @@ set l d = runIdentity . l (\_ -> Identity d) -- > fmap f = mapped %~ f -- > fmapDefault f = traverse %~ f -- --- > ghci> _2 %~ length \$ (1,"hello") --- > (1,5) +-- >>> _2 %~ length \$ (1,"hello") +-- (1,5) -- -- > (%~) :: Setter a b c d -> (c -> d) -> a -> b -- > (%~) :: Iso a b c d -> (c -> d) -> a -> b @@ -727,24 +727,24 @@ set l d = runIdentity . l (\_ -> Identity d) -- | Increment the target(s) of a numerically valued 'Lens', Setter' or 'Traversal' -- --- > ghci> _1 +~ 1 \$ (1,2) --- > (2,2) +-- >>> _1 +~ 1 \$ (1,2) +-- (2,2) (+~) :: Num c => Setter a b c c -> c -> a -> b l +~ n = adjust l (+ n) {-# INLINE (+~) #-} -- | Multiply the target(s) of a numerically valued 'Lens', 'Iso', 'Setter' or 'Traversal' -- --- > ghci> _2 *~ 4 \$ (1,2) --- > (1,8) +-- >>> _2 *~ 4 \$ (1,2) +-- (1,8) (*~) :: Num c => Setter a b c c -> c -> a -> b l *~ n = adjust l (* n) {-# INLINE (*~) #-} -- | Decrement the target(s) of a numerically valued 'Lens', 'Iso', 'Setter' or 'Traversal' -- --- > ghci> _1 -~ 2 \$ (1,2) --- > (-1,2) +-- >>> _1 -~ 2 \$ (1,2) +-- (-1,2) (-~) :: Num c => Setter a b c c -> c -> a -> b l -~ n = adjust l (subtract n) {-# INLINE (-~) #-} @@ -888,8 +888,8 @@ a ^. l = getConst (l Const a) -- | This is a lens that can change the value (and type) of the first field of -- a pair. -- --- > ghci> (1,2)^._1 --- > 1 +-- >>> (1,2)^._1 +-- 1 -- -- > ghci> _1 +~ "hello" \$ (1,2) -- > ("hello",2) @@ -914,8 +914,8 @@ _2 f (c,a) = (,) c <\$> f a -- -- Attempts to access beyond the range of the 'Traversal' will cause an error. -- --- > ghci> [[1],[3,4]]^.elementOf (traverse.traverse) 1 --- > 3 +-- >>> [[1],[3,4]]^.elementOf (traverse.traverse) 1 +-- 3 elementOf :: Functor f => LensLike (ElementOf f) a b c c -> Int -> LensLike f a b c c elementOf l i f a = case getElementOf (l go a) 0 of Found _ fb -> fb
 @@ -24,8 +24,8 @@ import Data.IntMap as IntMap -- | This 'Lens' can be used to read, write or delete the value associated with a key in an 'IntMap'. -- --- > ghci> fromList [(1,"hello")] ^.at 1 --- > Just "hello" +-- >>> fromList [(1,"hello")] ^.at 1 +-- Just "hello" -- -- > ghci> at 1 ^~ Just "hello" \$ mempty -- > fromList [(1,"hello")]
 @@ -37,8 +37,8 @@ contains k f s = go <\$> f (IntSet.member k s) where -- elements might change but you can manipulate it by reading using 'folded' and -- reindexing it via 'setmap'. -- --- > ghci> adjust members (+1) (fromList [1,2,3,4]) --- > fromList [2,3,4,5] +-- >>> adjust members (+1) (fromList [1,2,3,4]) +-- fromList [2,3,4,5] members :: Setter IntSet IntSet Int Int members = sets IntSet.map
 @@ -31,17 +31,17 @@ import Data.List -- | A lens reading and writing to the head of a /non-empty/ list -- --- > ghci> [1,2,3]^._head --- > 1 +-- >>> [1,2,3]^._head +-- 1 _head :: Simple Lens [a] a _head _ [] = error "_head: empty list" _head f (a:as) = (:as) <\$> f a {-# INLINE _head #-} -- | A lens reading and writing to the tail of a /non-empty/ list -- --- > ghci> _tail <~ [3,4,5] \$ [1,2] --- > [1,3,4,5] +-- >>> _tail <~ [3,4,5] \$ [1,2] +-- [1,3,4,5] _tail :: Simple Lens [a] [a] _tail _ [] = error "_tail: empty list" _tail f (a:as) = (a:) <\$> f as @@ -62,8 +62,8 @@ _init f as = (++ [Prelude.last as]) <\$> f (Prelude.init as) -- | Obtain a version of the list with the supplied value interspersed. -- --- > ghci> "abcde"^.interspersed ',' --- > "a,b,c,d,e" +-- >>> "abcde"^.interspersed ',' +-- "a,b,c,d,e" -- -- > xs^.interspersed a = intersperse a xs interspersed :: a -> Getter [a] [a]
 @@ -23,8 +23,8 @@ import Data.Map as Map -- | This 'Lens' can be used to read, write or delete the value associated with a key in a 'Map'. -- --- > ghci> Map.fromList [("hello",12)] ^.at "hello" --- > Just 12 +-- >>> Map.fromList [("hello",12)] ^.at "hello" +-- Just 12 -- -- > at :: Ord k => k -> (Maybe v -> f (Maybe v)) -> Map k v -> f (Map k v) at :: Ord k => k -> SimpleLens (Map k v) (Maybe v)
 @@ -36,8 +36,8 @@ contains k f s = go <\$> f (Set.member k s) where -- Sadly, you can't create a valid 'Traversal' for a 'Set', but you can -- manipulate it by reading using 'folded' and reindexing it via 'setmap'. -- --- > ghci> adjust members (+1) (fromList [1,2,3,4]) --- > fromList [2,3,4,5] +-- >>> adjust members (+1) (fromList [1,2,3,4]) +-- fromList [2,3,4,5] members :: (Ord i, Ord j) => Setter (Set i) (Set j) i j members = sets Set.map