summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorphadej <>2019-06-02 10:54:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2019-06-02 10:54:00 (GMT)
commitca3d7f334e063f51e945c72334ca28da9f94fc75 (patch)
tree01b3f835bc6a39dec70e9e65d90df90fad7571d0
version 1HEAD1master
-rwxr-xr-xCHANGELOG.md3
-rw-r--r--LICENSE30
-rw-r--r--src/Data/These/Lens.hs82
-rw-r--r--these-lens.cabal38
4 files changed, 153 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100755
index 0000000..a2aecd0
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,3 @@
+# 1
+
+Split out of `these` package.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..c699c39
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,30 @@
+Copyright (c)2012, C. McCann
+
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ * Neither the name of C. McCann nor the names of other
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/src/Data/These/Lens.hs b/src/Data/These/Lens.hs
new file mode 100644
index 0000000..91e1b82
--- /dev/null
+++ b/src/Data/These/Lens.hs
@@ -0,0 +1,82 @@
+{-# LANGUAGE Trustworthy #-}
+{-# OPTIONS_GHC -fno-warn-orphans #-}
+module Data.These.Lens (
+ -- * Traversals
+ here, there,
+
+ -- * Prisms
+ _This, _That, _These,
+ ) where
+
+import Prelude ()
+import Prelude.Compat
+
+import Control.Lens (Prism', Traversal, Swapped (..), iso, prism)
+import Data.These
+import Data.These.Combinators (swapThese)
+
+-- $setup
+-- >>> import Control.Lens
+
+-------------------------------------------------------------------------------
+-- Traversals
+-------------------------------------------------------------------------------
+
+-- | A 'Control.Lens.Traversal' of the first half of a 'These', suitable for use with "Control.Lens".
+--
+-- >>> over here show (That 1)
+-- That 1
+--
+-- >>> over here show (These 'a' 2)
+-- These "'a'" 2
+--
+here :: Traversal (These a c) (These b c) a b
+here f (This x) = This <$> f x
+here f (These x y) = flip These y <$> f x
+here _ (That x) = pure (That x)
+
+-- | A 'Control.Lens.Traversal' of the second half of a 'These', suitable for use with "Control.Lens".
+--
+-- @
+-- 'there' :: 'Control.Lens.Traversal' ('These' t b) ('These' t b) a b
+-- @
+--
+-- >>> over there show (That 1)
+-- That "1"
+--
+-- >>> over there show (These 'a' 2)
+-- These 'a' "2"
+--
+there :: Traversal (These c a) (These c b) a b
+there _ (This x) = pure (This x)
+there f (These x y) = These x <$> f y
+there f (That x) = That <$> f x
+
+-------------------------------------------------------------------------------
+-- Prisms
+-------------------------------------------------------------------------------
+
+-- | A 'Control.Lens.Prism'' selecting the 'This' constructor.
+--
+-- /Note:/ cannot change type.
+_This :: Prism' (These a b) a
+_This = prism This (these Right (Left . That) (\x y -> Left $ These x y))
+
+-- | A 'Control.Lens.Prism'' selecting the 'That' constructor.
+--
+-- /Note:/ cannot change type.
+_That :: Prism' (These a b) b
+_That = prism That (these (Left . This) Right (\x y -> Left $ These x y))
+
+-- | A 'Control.Lens.Prism'' selecting the 'These' constructor. 'These' names are ridiculous!
+--
+-- /Note:/ cannot change type.
+_These :: Prism' (These a b) (a, b)
+_These = prism (uncurry These) (these (Left . This) (Left . That) (\x y -> Right (x, y)))
+
+-------------------------------------------------------------------------------
+-- Orphans
+-------------------------------------------------------------------------------
+
+instance Swapped These where
+ swapped = iso swapThese swapThese
diff --git a/these-lens.cabal b/these-lens.cabal
new file mode 100644
index 0000000..4c3578c
--- /dev/null
+++ b/these-lens.cabal
@@ -0,0 +1,38 @@
+cabal-version: >=1.10
+name: these-lens
+version: 1
+synopsis: Lenses for These
+homepage: https://github.com/isomorphism/these
+license: BSD3
+license-file: LICENSE
+author: C. McCann, Oleg Grenrus
+maintainer: Oleg Grenrus <oleg.grenrus@iki.fi>
+category: Data, These, Lens
+build-type: Simple
+extra-source-files: CHANGELOG.md
+description: This package provides Prism and Traversals for @These@.
+tested-with:
+ GHC ==7.4.2 || ==7.6.3 || ==7.8.4 || ==7.10.3 || ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1
+
+source-repository head
+ type: git
+ location: https://github.com/isomorphism/these.git
+
+library
+ default-language: Haskell2010
+ ghc-options: -Wall
+
+ if impl(ghc >=8.0)
+ ghc-options: -Wno-trustworthy-safe
+
+ hs-source-dirs: src
+ exposed-modules: Data.These.Lens
+
+ -- ghc boot libs
+ build-depends: base >=4.5.1.0 && <4.13
+ build-depends: these >=1 && <1.1
+
+ -- other dependencies
+ build-depends:
+ base-compat >=0.10.5 && <0.11
+ , lens >=4.17.1 && <4.18