packages feed

microlens-each (empty) → 0.1.0.0

raw patch · 4 files changed

+156/−0 lines, 4 filesdep +basedep +microlenssetup-changed

Dependencies added: base, microlens

Files

+ 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-each.cabal view
@@ -0,0 +1,29 @@+name:                microlens-each+version:             0.1.0.0+synopsis:            'each' for microlens+description:+  This package contains @Each@ type class and the @each@ traversal.+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+-- copyright:           +category:            Data, Lenses+build-type:          Simple+-- extra-source-files:  README.md+cabal-version:       >=1.10++source-repository head+  type:                git+  location:            git://github.com/aelve/microlens.git++library+  exposed-modules:     Lens.Micro.Each+  -- other-modules:       +  -- other-extensions:    +  build-depends:       base >=4.4 && <5+                     , microlens ==0.1.*+  hs-source-dirs:      src+  default-language:    Haskell2010
+ src/Lens/Micro/Each.hs view
@@ -0,0 +1,95 @@+{-# LANGUAGE+  CPP+, DefaultSignatures+, MultiParamTypeClasses+, FunctionalDependencies+, GADTs+, FlexibleInstances+, UndecidableInstances+  #-}+++#ifndef MIN_VERSION_base+#define MIN_VERSION_base(x,y,z) 1+#endif+++module Lens.Micro.Each+(+  Each(..),+)+where+++import Control.Applicative+import Data.Complex+import Data.Traversable+import Lens.Micro+++{- |+A class to support 'each'. If you're writing a library, don't write instances+of this class which would be exported – other users won't be able to use them+if they use lens.+-}+class Each s t a b | s -> a, t -> b, s b -> t, t a -> s where+  {- |+'each' tries to be a universal 'Traversal' – it behaves like 'traverse' in+most situations, but also adds support for e.g. tuples with same-typed+values:++>>> (1,2) & each %~ succ+(2,3)++>>> ["x", "y", "z"] ^. each+"xyz"++However, note that 'each' doesn't work on /every/ instance of 'Traversable' –+the full list of instances can be found below.+  -}+  each :: Traversal s t a b+  default each :: (Traversable g, s ~ g a, t ~ g b) => Traversal s t a b+  each = traverse++-- | @'each' :: 'Traversal' (a,a) (b,b) a b@+instance (a~a', b~b') => Each (a,a') (b,b') a b where+  each f ~(a,b) = (,) <$> f a <*> f b+  {-# INLINE each #-}++-- | @'each' :: 'Traversal' (a,a,a) (b,b,b) a b@+instance (a~a2, a~a3, b~b2, b~b3) => Each (a,a2,a3) (b,b2,b3) a b where+  each f ~(a,b,c) = (,,) <$> f a <*> f b <*> f c+  {-# INLINE each #-}++-- | @'each' :: 'Traversal' (a,a,a,a) (b,b,b,b) a b@+instance (a~a2, a~a3, a~a4, b~b2, b~b3, b~b4) => Each (a,a2,a3,a4) (b,b2,b3,b4) a b where+  each f ~(a,b,c,d) = (,,,) <$> f a <*> f b <*> f c <*> f d+  {-# INLINE each #-}++-- | @'each' :: 'Traversal' (a,a,a,a,a) (b,b,b,b,b) a b@+instance (a~a2, a~a3, a~a4, a~a5, b~b2, b~b3, b~b4, b~b5) => Each (a,a2,a3,a4,a5) (b,b2,b3,b4,b5) a b where+  each f ~(a,b,c,d,e) = (,,,,) <$> f a <*> f b <*> f c <*> f d <*> f e+  {-# INLINE each #-}++-- | @'each' :: 'Traversal' (a,a,a,a,a,a) (b,b,b,b,b,b) a b@+instance (a~a2, a~a3, a~a4, a~a5, a~a6, b~b2, b~b3, b~b4, b~b5, b~b6) => Each (a,a2,a3,a4,a5,a6) (b,b2,b3,b4,b5,b6) a b where+  each f ~(a,b,c,d,e,g) = (,,,,,) <$> f a <*> f b <*> f c <*> f d <*> f e <*> f g+  {-# INLINE each #-}++#if MIN_VERSION_base(4,4,0)+-- | @'each' :: ('RealFloat' a, 'RealFloat' b) => 'Traversal' ('Complex' a) ('Complex' b) a b@+instance Each (Complex a) (Complex b) a b where+  each f (a :+ b) = (:+) <$> f a <*> f b+  {-# INLINE each #-}+#else+-- | @'each' :: 'Traversal' ('Complex' a) ('Complex' b) a b@+instance (RealFloat a, RealFloat b) => Each (Complex a) (Complex b) a b where+  each f (a :+ b) = (:+) <$> f a <*> f b+  {-# INLINE each #-}+#endif++-- | @'each' :: 'Traversal' [a] [b] a b@+instance Each [a] [b] a b++-- | @'each' :: 'Traversal' ('Maybe' a) ('Maybe' b) a b@+instance Each (Maybe a) (Maybe b) a b