lens-misc (empty) → 0.0.2.0
raw patch · 7 files changed
+156/−0 lines, 7 filesdep +basedep +lensdep +taggedsetup-changed
Dependencies added: base, lens, tagged, template-haskell
Files
- LICENSE +30/−0
- README.md +11/−0
- Setup.hs +2/−0
- lens-misc.cabal +31/−0
- src/Control/Lens/Misc.hs +9/−0
- src/Control/Lens/Misc/TH.hs +60/−0
- src/Control/Lens/Misc/Tagged.hs +13/−0
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Louis Pan (c) 2017++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 Louis Pan 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.
+ README.md view
@@ -0,0 +1,11 @@+[](https://hackage.haskell.org/package/lens-misc)+[](http://travis-ci.org/louispan/lens-misc)++Handy functions when using lens++# Changelog++* 0.0.2.0+ - Added `makeLenses_` and `makeClassy_'`, and `over'`.+* 0.0.1.0+ - Added `over'` for a type restricted (monomorphic) version of `over`
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ lens-misc.cabal view
@@ -0,0 +1,31 @@+name: lens-misc+version: 0.0.2.0+synopsis: Miscellaneous lens utilities.+description: Handy functions when using lens.+homepage: https://github.com/louispan/lens-misc#readme+license: BSD3+license-file: LICENSE+author: Louis Pan+maintainer: louis@pan.me+copyright: 2017 Louis Pan+category: Control+build-type: Simple+extra-source-files: README.md+cabal-version: >=1.10+tested-with: GHC == 8.0.1++library+ hs-source-dirs: src+ exposed-modules: Control.Lens.Misc+ , Control.Lens.Misc.Tagged+ , Control.Lens.Misc.TH+ build-depends: base >= 4.7 && < 5+ , lens >= 4+ , tagged >= 0.8+ , template-haskell >= 2.11.0.0+ ghc-options: -Wall+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/louispan/lens-misc
+ src/Control/Lens/Misc.hs view
@@ -0,0 +1,9 @@+{-# LANGUAGE RankNTypes #-}++module Control.Lens.Misc+ ( module Control.Lens.Misc.Tagged+ , module Control.Lens.Misc.TH+ ) where++import Control.Lens.Misc.Tagged+import Control.Lens.Misc.TH
+ src/Control/Lens/Misc/TH.hs view
@@ -0,0 +1,60 @@+module Control.Lens.Misc.TH where++import Control.Lens+import Control.Lens.Internal.FieldTH+import Data.Char+import Language.Haskell.TH++-- | type restricted version of 'over'+over' :: ASetter' s a -> (a -> a) -> s -> s+over' = over++-- | A 'LensRules' used by 'makeClassy_''.+classyRules_' :: LensRules+classyRules_' = classyRules_+ & lensClass .~ (over (mapped . both) mkName . classFun . nameBase)+ where+ classFun (x:xs) = Just ("Has" ++ x:xs, '_': toLower x:xs)+ classFun [] = Nothing++-- | Make lenses and traversals for a type, and create a class when the type+-- has no arguments. Works the same as 'makeClassy_' except that+-- the resulting *classy* lens is also prefixed with an underscore.+makeClassy_' :: Name -> DecsQ+makeClassy_' = makeFieldOptics classyRules_'++-- | A 'LensRules' used by 'makeLenses_'.+lensRules_ :: LensRules+lensRules_ = lensRules+ & lensField .~ \_ _ n -> [TopName (mkName ('_':nameBase n))]+++-- | Build lenses (and traversals) with a sensible default configuration.+-- Works the same as 'makeLenses' except that+-- the resulting lens is also prefixed with an underscore.+--+-- /e.g./+--+-- @+-- data FooBar+-- = Foo { x, y :: 'Int' }+-- | Bar { x :: 'Int' }+-- 'makeLenses' ''FooBar+-- @+--+-- will create+--+-- @+-- _x :: 'Lens'' FooBar 'Int'+-- _x f (Foo a b) = (\\a\' -> Foo a\' b) \<$\> f a+-- _x f (Bar a) = Bar \<$\> f a+-- _y :: 'Traversal'' FooBar 'Int'+-- _y f (Foo a b) = (\\b\' -> Foo a b\') \<$\> f b+-- _y _ c\@(Bar _) = pure c+-- @+--+-- @+-- 'makeLenses_' = 'makeLensesWith' 'lensRules_'+-- @+makeLenses_ :: Name -> DecsQ+makeLenses_ = makeFieldOptics lensRules_
+ src/Control/Lens/Misc/Tagged.hs view
@@ -0,0 +1,13 @@+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE RankNTypes #-}++module Control.Lens.Misc.Tagged where++import Control.Lens+import Data.Tagged++_Tagged' :: Iso' (Tagged t a) a+_Tagged' = iso unTagged Tagged++_Tagged :: Iso (Tagged t a) (Tagged t b) a b+_Tagged = iso unTagged Tagged