Skip to content

Commit

Permalink
Remove references to remit from the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
ehird committed Jan 12, 2013
1 parent 3c87e15 commit 544cdaa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/Control/Lens/Fold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ hasn't l = getAll #. foldMapOf l (\_ -> All False)

-- | This converts a 'Fold' to a 'Getter' that returns the first element if it
-- exists as a 'Maybe'.
pre :: Getting (Endo r) s t a b -> Getting r s t (Maybe a) (Maybe b)
pre :: Getting (Leftmost r) s t a b -> Getting r s t (Maybe a) (Maybe b)
pre l f = (Accessor #. flip appEndo (runAccessor (f Nothing)) .# runAccessor) `rmap` l (dimap Just (Accessor #. Endo #. const .# runAccessor) f)

------------------------------------------------------------------------------
Expand Down Expand Up @@ -1311,8 +1311,8 @@ pre l f = (Accessor #. flip appEndo (runAccessor (f Nothing)) .# runAccessor) `r
-- 'preview' :: 'MonadReader' s m => 'Iso'' s a -> m ('Maybe' a)
-- 'preview' :: 'MonadReader' s m => 'Traversal'' s a -> m ('Maybe' a)
-- @
preview :: MonadReader s m => Getting (Endo (Maybe a)) s t a b -> m (Maybe a)
preview l = asks (foldrOf l (\x _ -> Just x) Nothing)
preview :: MonadReader s m => Getting (Leftmost a) s t a b -> m (Maybe a)
preview l = asks (getLeftmost . foldMapOf l LLeaf)
{-# INLINE preview #-}

-- | Retrieve a function of the first value targeted by a 'Fold' or
Expand Down Expand Up @@ -1394,7 +1394,7 @@ preuses l f = gets (previews l f)
-- This has no practical impact on a 'Getter', 'Setter', 'Lens' or 'Iso'.
--
-- /NB:/ To write back through an 'Iso', you want to use 'Control.Lens.Isomorphic.from'.
-- Similarly, to write back through an 'Prism', you want to use 'Control.Lens.Prism.remit'.
-- Similarly, to write back through an 'Prism', you want to use 'Control.Lens.Review.re'.
backwards :: (Profunctor p, Profunctor q) => Overloading p q (Backwards f) s t a b -> Overloading p q f s t a b
backwards l f = forwards #. l (Backwards #. f)
{-# INLINE backwards #-}
Expand Down
27 changes: 25 additions & 2 deletions src/Control/Lens/Internal/Fold.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Control.Lens.Internal.Fold
, Sequenced(..)
, Max(..), getMax
, Min(..), getMin
, Leftmost(..), getLeftmost
, Rightmost(..), getRightmost
) where

Expand Down Expand Up @@ -110,9 +111,32 @@ getMax (Max a) = Just a
{-# INLINE getMax #-}

------------------------------------------------------------------------------
-- Rightmost
-- Leftmost and Rightmost
------------------------------------------------------------------------------

-- | Used for 'Control.Lens.Fold.preview'
data Leftmost a = LPure | LLeaf a | LStep (Leftmost a)

instance Monoid (Leftmost a) where
mempty = LPure
{-# INLINE mempty #-}
mappend x y = LStep $ case x of
RPure -> y
RLeaf _ -> x
RStep x' -> case y of
-- The last two cases make firstOf produce a Just as soon as any element
-- is encountered, and possibly serve as a micro-optimisation; this
-- behaviour can be disabled by replacing them with _ -> mappend x y'.
-- Note that this means that firstOf (backwards folded) [1..] is Just _|_.
LPure -> x'
LLeaf a -> LLeaf $ fromMaybe a (getLeftmost x')
LStep x' -> mappend x' y'

getLeftmost :: Leftmost a -> Maybe a
getLeftmost LPure = Nothing
getLeftmost (LLeaf a) = Just a
getLeftmost (LStep x) = getLeftmost x

-- | Used for 'Control.Lens.Fold.lastOf'
data Rightmost a = RPure | RLeaf a | RStep (Rightmost a)

Expand All @@ -135,4 +159,3 @@ getRightmost :: Rightmost a -> Maybe a
getRightmost RPure = Nothing
getRightmost (RLeaf a) = Just a
getRightmost (RStep x) = getRightmost x

4 changes: 2 additions & 2 deletions src/Control/Lens/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,12 @@ type Iso' s a = Iso s s a a
------------------------------------------------------------------------------

-- | A 'Prism' @l@ is a 0-or-1 target 'Traversal' that can also be turned
-- around with 'Control.Lens.Review.remit' to obtain a 'Getter' in the
-- around with 'Control.Lens.Review.re' to obtain a 'Getter' in the
-- opposite direction.
--
-- There are two laws that a 'Prism' should satisfy:
--
-- First, if I 'Control.Lens.Review.remit' or 'Control.Lens.Prism.review' a value with a 'Prism' and then 'Control.Lens.Prism.preview' or use ('Control.Lens.Fold.^?'), I will get it back:
-- First, if I 'Control.Lens.Review.re' or 'Control.Lens.Prism.review' a value with a 'Prism' and then 'Control.Lens.Prism.preview' or use ('Control.Lens.Fold.^?'), I will get it back:
--
-- * @'Control.Lens.Prism.preview' l ('Control.Lens.Prism.review' l b) ≡ 'Just' b@
--
Expand Down

0 comments on commit 544cdaa

Please sign in to comment.