Browse files

inverting the roles of under and over to make more idiomatic code.

  • Loading branch information...
1 parent 32cc6ba commit ef349048d63602403c3430d4b074241b12ab5b1f @ekmett committed Aug 13, 2012
Showing with 46 additions and 46 deletions.
  1. +7 −7 src/Control/Lens/Iso.hs
  2. +31 −31 src/Control/Lens/Setter.hs
  3. +4 −4 src/Data/Array/Lens.hs
  4. +2 −2 src/Data/Bits/Lens.hs
  5. +1 −1 src/Data/IntSet/Lens.hs
  6. +1 −1 src/Data/Set/Lens.hs
View
14 src/Control/Lens/Iso.hs
@@ -18,7 +18,7 @@ module Control.Lens.Iso
, isos
, au
, auf
- , over
+ , under
-- ** Combinators
, via
, from
@@ -185,14 +185,14 @@ auf :: Simple Iso a b -> ((d -> b) -> c -> b) -> (d -> a) -> c -> a
auf l f g e = f (view l . g) e ^. from l
{-# INLINE auf #-}
--- | The opposite of working 'under' an isomorphism.
+-- | The opposite of working 'over' a Setter is working 'under' an Isomorphism.
--
--- @'over' = 'under' . 'from'@
+-- @'under' = 'over' . 'from'@
--
--- @'over' :: Iso a b c d -> (a -> b) -> (c -> d)@
-over :: Isomorphism (c -> Mutator d) (a -> Mutator b) -> (a -> b) -> c -> d
-over = under . from
-{-# INLINE over #-}
+-- @'under' :: Iso a b c d -> (a -> b) -> (c -> d)@
+under :: Isomorphism (c -> Mutator d) (a -> Mutator b) -> (a -> b) -> c -> d
+under = over . from
+{-# INLINE under #-}
-----------------------------------------------------------------------------
-- Isomorphisms
View
62 src/Control/Lens/Setter.hs
@@ -31,7 +31,7 @@ module Control.Lens.Setter
-- * Common Setters
, mapped
-- * Functional Combinators
- , under
+ , over
, mapOf
, set
, (.~), (%~)
@@ -73,8 +73,8 @@ infixr 2 <~
-- However, two 'Functor' laws apply to a 'Setter':
--
-- @
--- 'under' l 'id' = 'id'
--- 'under' l f . 'under' l g = 'under' l (f . g)
+-- 'over' l 'id' = 'id'
+-- 'over' l f . 'over' l g = 'over' l (f . g)
-- @
--
-- These an be stated more directly:
@@ -162,8 +162,8 @@ instance Settable Mutator where
-- | This setter can be used to map over all of the values in a 'Functor'.
--
-- @
--- 'fmap' = 'under' 'mapped'
--- 'Data.Traversable.fmapDefault' = 'under' 'Data.Traversable.traverse'
+-- 'fmap' = 'over' 'mapped'
+-- 'Data.Traversable.fmapDefault' = 'over' 'Data.Traversable.traverse'
-- ('<$') = 'set' 'mapped'
-- @
mapped :: Functor f => Setter (f a) (f b) a b
@@ -182,8 +182,8 @@ mapped = sets fmap
-- Equational reasoning:
--
-- @
--- 'sets' . 'under' = 'id'
--- 'under' . 'sets' = 'id'
+-- 'sets' . 'over' = 'id'
+-- 'over' . 'sets' = 'id'
-- @
--
-- Another way to view 'sets' is that it takes a \"semantic editor combinator\"
@@ -200,25 +200,25 @@ sets f g = pure . f (untainted . g)
-- with a function.
--
-- @
--- 'fmap' = 'under' 'mapped'
--- 'Data.Traversable.fmapDefault' = 'under' 'Data.Traversable.traverse'
--- 'sets' . 'under' = 'id'
--- 'under' . 'sets' = 'id'
+-- 'fmap' = 'over' 'mapped'
+-- 'Data.Traversable.fmapDefault' = 'over' 'Data.Traversable.traverse'
+-- 'sets' . 'over' = 'id'
+-- 'over' . 'sets' = 'id'
-- @
--
--- Another way to view 'under' is to say that it transformers a 'Setter' into a
+-- Another way to view 'over' is to say that it transformers a 'Setter' into a
-- \"semantic editor combinator\".
--
--- @'under' :: 'Setter' a b c d -> (c -> d) -> a -> b@
-under :: Setting a b c d -> (c -> d) -> a -> b
-under l f = runMutator . l (Mutator . f)
-{-# INLINE under #-}
+-- @'over' :: 'Setter' a b c d -> (c -> d) -> a -> b@
+over :: Setting a b c d -> (c -> d) -> a -> b
+over l f = runMutator . l (Mutator . f)
+{-# INLINE over #-}
-- | Modify the target of a 'Control.Lens.Type.Lens' or all the targets of a 'Setter' or 'Control.Lens.Traversal.Traversal'
--- with a function. This is an alias for 'under' that is provided for consistency.
+-- with a function. This is an alias for 'over' that is provided for consistency.
--
-- @
--- 'mapOf' = 'under'
+-- 'mapOf' = 'over'
-- 'fmap' = 'mapOf' 'mapped'
-- 'fmapDefault' = 'mapOf' 'traverse'
-- 'sets' . 'mapOf' = 'id'
@@ -232,7 +232,7 @@ under l f = runMutator . l (Mutator . f)
-- mapOf :: 'Control.Lens.Traversal.Traversal' a b c d -> (c -> d) -> a -> b
-- @
mapOf :: Setting a b c d -> (c -> d) -> a -> b
-mapOf = under
+mapOf = over
{-# INLINE mapOf #-}
-- | Replace the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter'
@@ -263,7 +263,7 @@ set l d = runMutator . l (\_ -> Mutator d)
-- | Modifies the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter' or
-- 'Control.Lens.Traversal.Traversal' with a user supplied function.
--
--- This is an infix version of 'under'
+-- This is an infix version of 'over'
--
-- @
-- 'fmap' f = 'mapped' '%~' f
@@ -281,7 +281,7 @@ set l d = runMutator . l (\_ -> Mutator d)
-- (%~) :: 'Control.Lens.Traversal.Traversal' a b c d -> (c -> d) -> a -> b
-- @
(%~) :: Setting a b c d -> (c -> d) -> a -> b
-(%~) = under
+(%~) = over
{-# INLINE (%~) #-}
-- | Replace the target of a 'Control.Lens.Type.Lens' or all of the targets of a 'Setter'
@@ -334,7 +334,7 @@ l <.~ d = \a -> (d, l .~ d $ a)
-- (+~) :: Num c => 'Control.Lens.Traversal.Traversal' a b c c -> c -> a -> b
-- @
(+~) :: Num c => Setting a b c c -> c -> a -> b
-l +~ n = under l (+ n)
+l +~ n = over l (+ n)
{-# INLINE (+~) #-}
-- | Multiply the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal'
@@ -350,7 +350,7 @@ l +~ n = under l (+ n)
-- (*~) :: 'Num' c => 'Control.Lens.Traversal.Traversal' a b c c -> c -> a -> b
-- @
(*~) :: Num c => Setting a b c c -> c -> a -> b
-l *~ n = under l (* n)
+l *~ n = over l (* n)
{-# INLINE (*~) #-}
-- | Decrement the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal'
@@ -366,7 +366,7 @@ l *~ n = under l (* n)
-- (-~) :: 'Num' c => 'Control.Lens.Traversal.Traversal' a b c c -> c -> a -> b
-- @
(-~) :: Num c => Setting a b c c -> c -> a -> b
-l -~ n = under l (subtract n)
+l -~ n = over l (subtract n)
{-# INLINE (-~) #-}
-- | Divide the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Control.Lens.Iso.Iso', 'Setter' or 'Control.Lens.Traversal.Traversal'
@@ -378,15 +378,15 @@ l -~ n = under l (subtract n)
-- (//~) :: 'Fractional' c => 'Control.Lens.Traversal.Traversal' a b c c -> c -> a -> b
-- @
(//~) :: Fractional c => Setting a b c c -> c -> a -> b
-l //~ n = under l (/ n)
+l //~ n = over l (/ n)
-- | Raise the target(s) of a numerically valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to a non-negative integral power
--
-- >>> import Control.Lens
-- >>> _2 ^~ 2 $ (1,3)
-- (1,9)
(^~) :: (Num c, Integral e) => Setting a b c c -> e -> a -> b
-l ^~ n = under l (^ n)
+l ^~ n = over l (^ n)
{-# INLINE (^~) #-}
-- | Raise the target(s) of a fractionally valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to an integral power
@@ -403,7 +403,7 @@ l ^~ n = under l (^ n)
-- @
--
(^^~) :: (Fractional c, Integral e) => Setting a b c c -> e -> a -> b
-l ^^~ n = under l (^^ n)
+l ^^~ n = over l (^^ n)
{-# INLINE (^^~) #-}
-- | Raise the target(s) of a floating-point valued 'Control.Lens.Type.Lens', 'Setter' or 'Control.Lens.Traversal.Traversal' to an arbitrary power.
@@ -419,7 +419,7 @@ l ^^~ n = under l (^^ n)
-- (**~) :: 'Floating' c => 'Control.Lens.Traversal.Traversal' a b c c -> c -> a -> b
-- @
(**~) :: Floating c => Setting a b c c -> c -> a -> b
-l **~ n = under l (** n)
+l **~ n = over l (** n)
{-# INLINE (**~) #-}
-- | Logically '||' the target(s) of a 'Bool'-valued 'Control.Lens.Type.Lens' or 'Setter'
@@ -439,7 +439,7 @@ l **~ n = under l (** n)
-- (||~):: 'Control.Lens.Traversal.Traversal' a b 'Bool' 'Bool' -> 'Bool' -> a -> b
-- @
(||~):: Setting a b Bool Bool -> Bool -> a -> b
-l ||~ n = under l (|| n)
+l ||~ n = over l (|| n)
{-# INLINE (||~) #-}
-- | Logically '&&' the target(s) of a 'Bool'-valued 'Control.Lens.Type.Lens' or 'Setter'
@@ -459,7 +459,7 @@ l ||~ n = under l (|| n)
-- (&&~):: 'Control.Lens.Traversal.Traversal' a b 'Bool' 'Bool' -> 'Bool' -> a -> b
-- @
(&&~) :: Setting a b Bool Bool -> Bool -> a -> b
-l &&~ n = under l (&& n)
+l &&~ n = over l (&& n)
{-# INLINE (&&~) #-}
-- | Modify the target of a monoidally valued by 'mappend'ing another value.
@@ -475,7 +475,7 @@ l &&~ n = under l (&& n)
-- (<>~) :: 'Monoid' c => 'Control.Lens.Traversal.Traversal' a b c c -> c -> a -> b
-- @
(<>~) :: Monoid c => Setting a b c c -> c -> a -> b
-l <>~ n = under l (`mappend` n)
+l <>~ n = over l (`mappend` n)
{-# INLINE (<>~) #-}
------------------------------------------------------------------------------
View
8 src/Data/Array/Lens.hs
@@ -44,21 +44,21 @@ ix i f arr = (\e -> arr // [(i,e)]) <$> f (arr ! i)
--
-- This is a /contravariant/ 'Setter'.
--
--- @'ixmap' = 'under' . 'ixmapped'@
+-- @'ixmap' = 'over' . 'ixmapped'@
--
-- @'ixmapped' = 'sets' . 'ixmap'@
--
--- @'under' ('ixmapped' b) f arr '!' i = arr '!' f i@
+-- @'over' ('ixmapped' b) f arr '!' i = arr '!' f i@
--
--- @'bounds' ('under' ('ixmapped' b) f arr) = b@
+-- @'bounds' ('over' ('ixmapped' b) f arr) = b@
ixmapped :: (IArray a e, Ix i, Ix j) => (i,i) -> Setter (a j e) (a i e) i j
ixmapped = sets . ixmap
{-# INLINE ixmapped #-}
-- | An 'IndexedTraversal' of the elements of an 'IArray', using the
-- index into the array as the index of the traversal.
--
--- @'amap' = 'under' 'traverseArray'@
+-- @'amap' = 'over' 'traverseArray'@
traverseArray :: (IArray a c, IArray a d, Ix i) => IndexedTraversal i (a i c) (a i d) c d
traverseArray = index $ \f arr -> array (bounds arr) <$> traverse (\(i,a) -> (,) i <$> f i a) (assocs arr)
{-# INLINE traverseArray #-}
View
4 src/Data/Bits/Lens.hs
@@ -30,15 +30,15 @@ infix 4 |=, &=
-- >>> _2 |~ 6 $ ("hello",3)
-- ("hello",7)
(|~):: Bits c => Setting a b c c -> c -> a -> b
-l |~ n = under l (.|. n)
+l |~ n = over l (.|. n)
{-# INLINE (|~) #-}
-- | Bitwise '.&.' the target(s) of a 'Bool'-valued 'Lens' or 'Setter'
--
-- >>> _2 &~ 7 $ ("hello",254)
-- ("hello",6)
(&~) :: Bits c => Setting a b c c -> c -> a -> b
-l &~ n = under l (.&. n)
+l &~ n = over l (.&. n)
{-# INLINE (&~) #-}
-- | Modify the target(s) of a 'Simple' 'Lens', 'Setter' or 'Traversal' by computing its bitwise '.&.' with another value.
View
2 src/Data/IntSet/Lens.hs
@@ -45,7 +45,7 @@ members = folding IntSet.toAscList
-- elements might change but you can manipulate it by reading using 'folded' and
-- reindexing it via 'setmap'.
--
--- >>> under setmapped (+1) (fromList [1,2,3,4])
+-- >>> over setmapped (+1) (fromList [1,2,3,4])
-- fromList [2,3,4,5]
setmapped :: Simple Setter IntSet Int
setmapped = sets IntSet.map
View
2 src/Data/Set/Lens.hs
@@ -40,7 +40,7 @@ contains k f s = go <$> f (Set.member k s) where
-- manipulate it by reading using 'folded' and reindexing it via 'setmap'.
--
-- >>> :m + Data.Set.Lens Control.Lens
--- >>> under setmapped (+1) (fromList [1,2,3,4])
+-- >>> over setmapped (+1) (fromList [1,2,3,4])
-- fromList [2,3,4,5]
setmapped :: (Ord i, Ord j) => Setter (Set i) (Set j) i j
setmapped = sets Set.map

0 comments on commit ef34904

Please sign in to comment.