packages feed

microlens-contra (empty) → 0.1.0.0

raw patch · 5 files changed

+134/−0 lines, 5 filesdep +basedep +contravariantdep +microlenssetup-changed

Dependencies added: base, contravariant, microlens

Files

+ CHANGELOG.md view
@@ -0,0 +1,3 @@+# 0.1.0.0++Initial release.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Artyom++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 Artyom 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.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ microlens-contra.cabal view
@@ -0,0 +1,40 @@+name:                microlens-contra+version:             0.1.0.0+synopsis:            True folds and getters for microlens+description:+  This package provides @Fold@ and @Getter@ that are fully compatible with lens; the downside is that this package depends on contravariant, which in its turn depends on a lot of other packages (but still less than lens).+  .+  The difference between @Fold@ and @SimpleFold@ is that you can use e.g. @takingWhile@\/@droppingWhile@ and @backwards@ on the former but not on the latter. Most functions from lens that work with @Fold@ would work with @SimpleFold@ as well, tho.+  .+  This package is a part of the <http://hackage.haskell.org/package/microlens microlens> family; see the readme <https://github.com/aelve/microlens#readme on Github>.+license:             BSD3+license-file:        LICENSE+author:              Artyom+maintainer:          Artyom <yom@artyom.me>+homepage:            http://github.com/aelve/microlens+bug-reports:         http://github.com/aelve/microlens/issues+category:            Data, Lenses+build-type:          Simple+extra-source-files:+  CHANGELOG.md+cabal-version:       >=1.10++source-repository head+  type:                git+  location:            git://github.com/aelve/microlens.git++library+  exposed-modules:     Lens.Micro.Contra+  -- other-modules:+  -- other-extensions:+  build-depends:       base >=4.5 && <5+                     , contravariant >=1.3 && <2+                     , microlens >=0.4 && <0.5++  ghc-options:+    -Wall -fwarn-tabs+    -O2 -fdicts-cheap -funbox-strict-fields+    -fmax-simplifier-iterations=10++  hs-source-dirs:      src+  default-language:    Haskell2010
+ src/Lens/Micro/Contra.hs view
@@ -0,0 +1,59 @@+{-# LANGUAGE+CPP,+RankNTypes,+Safe+  #-}+++{- |+This module provides types and functions that require 'Contravariant'; they aren't included in the main microlens package because <http://hackage.haskell.org/package/contravariant contravariant> has a lot of dependencies.+-}+module Lens.Micro.Contra+(+  -- * Getter+  Getter,+  fromSimpleGetter,++  -- * Fold+  Fold,+  fromSimpleFold,+)+where+++import Lens.Micro+import Lens.Micro.Extras (view)++import Data.Foldable (traverse_)+import Data.Functor.Contravariant (phantom, Contravariant)++#if __GLASGOW_HASKELL__ < 710+import Control.Applicative+#endif+++{- |+This is the same thing as 'SimpleGetter' but more generalised (so that it would fully match the type used in lens).+-}+type Getter s a =+  forall f. (Contravariant f, Functor f) => (a -> f a) -> s -> f s++{- |+Turn a 'SimpleGetter' into a true 'Getter'.+-}+fromSimpleGetter :: SimpleGetter s a -> Getter s a+fromSimpleGetter g f = phantom . f . view g+{-# INLINE fromSimpleGetter #-}++{- |+This is the same thing as 'SimpleFold' but more generalised (so that it would fully match the type used in lens). See documentation of 'SimpleFold' for the list of functions that work on 'Fold' but don't work on 'SimpleFold'.+-}+type Fold s a =+  forall f. (Contravariant f, Applicative f) => (a -> f a) -> s -> f s++{- |+Turn a 'SimpleFold' into a true 'Fold'.+-}+fromSimpleFold :: SimpleFold s a -> Fold s a+fromSimpleFold g f = phantom . traverse_ f . toListOf g+{-# INLINE fromSimpleFold #-}