Skip to content

Commit

Permalink
Added only and united. Added devoid examples.
Browse files Browse the repository at this point in the history
Conflicts:

	CHANGELOG.markdown
  • Loading branch information
ekmett committed Feb 15, 2013
1 parent b16ecd9 commit 9336d0f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.markdown
Expand Up @@ -2,8 +2,9 @@
----- -----
* Fixed an issue with `DefaultSignatures` being used outside of the appropriate `#ifdef` that caused compilation issues on GHC 7.0.2. * Fixed an issue with `DefaultSignatures` being used outside of the appropriate `#ifdef` that caused compilation issues on GHC 7.0.2.
* Generalized the signature of `prism'` * Generalized the signature of `prism'`
* Added `\_Void` to `Control.Lens.Prism` and `devoid` to `Control.Lens.Lens`. * Added `\_Void` and `only` to `Control.Lens.Prism` and `devoid` to `Control.Lens.Lens`.
* Added `\_Nothing` to `Control.Lens.Prism`. * Added `\_Nothing` to `Control.Lens.Prism`.
* Added `devoid` and `united` to `Control.Lens.Lens`.


3.8.5 3.8.5
----- -----
Expand Down
24 changes: 23 additions & 1 deletion src/Control/Lens/Lens.hs
Expand Up @@ -104,6 +104,7 @@ module Control.Lens.Lens


-- * Common Lenses -- * Common Lenses
, devoid , devoid
, united


-- * Context -- * Context
, Context(..) , Context(..)
Expand Down Expand Up @@ -938,6 +939,27 @@ l <#= b = do
{-# INLINE (<#=) #-} {-# INLINE (<#=) #-}


-- | There is a field for every type in the 'Void'. Very zen. -- | There is a field for every type in the 'Void'. Very zen.
devoid :: Lens Void Void a b --
-- >>> [] & mapped.devoid +~ 1
-- []
--
-- Nothing & mapped.devoid %~ abs
-- Nothing
--
-- @
-- 'devoid' :: 'Lens'' 'Void' a
-- @
devoid :: Over p f Void Void a b
devoid _ = absurd devoid _ = absurd
{-# INLINE devoid #-} {-# INLINE devoid #-}

-- | We can always retrieve a @()@ from any type.
--
-- >>> "hello"^.united
-- ()
--
-- >>> "hello" & united .~ ()
-- "hello"
united :: Lens' a ()
united f v = f () <&> \ () -> v
{-# INLINE united #-}
12 changes: 12 additions & 0 deletions src/Control/Lens/Prism.hs
Expand Up @@ -33,6 +33,7 @@ module Control.Lens.Prism
, _Just , _Just
, _Nothing , _Nothing
, _Void , _Void
, only
-- * Prismatic profunctors -- * Prismatic profunctors
, Choice(..) , Choice(..)
) where ) where
Expand All @@ -42,6 +43,7 @@ import Control.Lens.Combinators
import Control.Lens.Internal.Prism import Control.Lens.Internal.Prism
import Control.Lens.Internal.Setter import Control.Lens.Internal.Setter
import Control.Lens.Type import Control.Lens.Type
import Control.Monad
import Data.Bifunctor import Data.Bifunctor
import Data.Profunctor import Data.Profunctor
import Data.Void import Data.Void
Expand Down Expand Up @@ -255,3 +257,13 @@ _Nothing = prism' (const Nothing) $ maybe (Just ()) (const Nothing)
_Void :: Prism s s a Void _Void :: Prism s s a Void
_Void = prism absurd Left _Void = prism absurd Left
{-# INLINE _Void #-} {-# INLINE _Void #-}

-- | This 'Prism' compares for exact equality with a given value.
--
-- >>> only 4 # ()
-- 4
--
-- >>> 5 ^? only 4
-- Nothing
only :: Eq a => a -> Prism' a ()
only a = prism' (\() -> a) $ guard . (a ==)

0 comments on commit 9336d0f

Please sign in to comment.