packages feed

smash-lens (empty) → 0.1.0.0

raw patch · 9 files changed

+437/−0 lines, 9 filesdep +basedep +lensdep +smashsetup-changed

Dependencies added: base, lens, smash

Files

+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for smash-lens++## 0.1.0.0 -- YYYY-mm-dd++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2020, Emily Pillmore++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 Emily Pillmore 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,9 @@+# smash-lens: Optics for the smash library+++[![Build Status](https://travis-ci.com/emilypi/smash.svg?branch=master)](https://travis-ci.com/emilypi/smash)+[![Hackage](https://img.shields.io/hackage/v/smash-lens.svg)](https://hackage.haskell.org/package/smash-lens)++++This library provides optics for the [smash](https://hackage.haskell.org/package/smash).
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ smash-lens.cabal view
@@ -0,0 +1,52 @@+cabal-version:       2.0+++name:                smash-lens+version:             0.1.0.0+synopsis:            Optics for the `smash` library+description:+  Prisms, Traversals, and combinators for the `smash` library.++homepage:            https://github.com/emilypi/smash+bug-reports:         https://github.com/emilypi/smash/issues+license:             BSD3+license-file:        LICENSE+author:              Emily Pillmore+maintainer:          emilypi@cohomolo.gy+copyright:           (c) 2020 Emily Pillmore <emilypi@cohomolo.gy>+category:            Data+build-type:          Simple+extra-source-files:+  CHANGELOG.md+  README.md+++tested-with:+  GHC ==8.2.2 || ==8.4.3 || ==8.4.4 || ==8.6.3 || ==8.6.5 || ==8.8.3 || ==8.10.1+++source-repository head+  type:     git+  location: https://github.com/emilypi/smash.git++library+  exposed-modules:     Data.Can.Lens+                     , Data.Smash.Lens+                     , Data.Wedge.Lens+  -- other-modules:+  -- other-extensions:+  build-depends:       base >=4.10 && <5.0+                     , lens >=4.0  && <5.0+                     , smash ^>= 0.1++  hs-source-dirs:      src+  default-language:    Haskell2010++  ghc-options:         -Wall++test-suite smash-lens-test+  default-language:    Haskell2010+  type:                exitcode-stdio-1.0+  hs-source-dirs:      test+  main-is:             MyLibTest.hs+  build-depends:       base >=4.10 && <5.0
+ src/Data/Can/Lens.hs view
@@ -0,0 +1,136 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- |+-- Module       : Data.Can.Lens+-- Copyright 	: (c) 2020 Emily Pillmore+-- License	: BSD-style+--+-- Maintainer	: Emily Pillmore <emilypi@cohomolo.gy>+-- Stability	: Experimental+-- Portability	: FlexibleInstances, MPTC, Type Families, UndecideableInstances+--+-- 'Prism's and 'Traversal's for the 'Can' datatype.+--+module Data.Can.Lens+( -- * Prisms+  _Non+, _One+, _Eno+, _Two+  -- * Traversals+, oneing+, enoing+, twoed+, twoing+) where+++import Control.Lens++import Data.Can++-- ------------------------------------------------------------------- --+-- Traversals++-- | A 'Control.Lens.Traversal' of the first parameter, suitable for use+-- with "Control.Lens".+--+oneing :: Traversal (Can a c) (Can b c) a b+oneing f = \case+  Non -> pure Non+  One a -> One <$> f a+  Eno c -> pure (Eno c)+  Two a c -> flip Two c <$> f a++-- | A 'Control.Lens.Traversal' of the second parameter, suitable for use+-- with "Control.Lens".+--+enoing :: Traversal (Can a b) (Can a c) b c+enoing f = \case+  Non -> pure Non+  One a -> pure (One a)+  Eno b -> Eno <$> f b+  Two a b -> Two a <$> f b++-- | A 'Control.Lens.Traversal' of the pair, suitable for use+-- with "Control.Lens".+--+twoed :: Traversal' (Can a b) (a,b)+twoed f = \case+  Non -> pure Non+  One a -> pure (One a)+  Eno b -> pure (Eno b)+  Two a b -> uncurry Two <$> f (a,b)++-- | A 'Control.Lens.Traversal' of the pair ala 'both', suitable for use+-- with "Control.Lens".+--+twoing :: Traversal (Can a a) (Can b b) a b+twoing f = \case+  Non -> pure Non+  One a -> One <$> f a+  Eno a -> Eno <$> f a+  Two a b -> Two <$> f a <*> f b++-- ------------------------------------------------------------------- --+-- Prisms++-- | A 'Control.Lens.Prism'' selecting the 'Non' constructor.+--+-- /Note:/ cannot change type.+--+_Non :: Prism' (Can a b) ()+_Non = prism (const Non) $ \case+  Non -> Right ()+  One a -> Left (One a)+  Eno b -> Left (Eno b)+  Two a b -> Left (Two a b)++-- | A 'Control.Lens.Prism'' selecting the 'One' constructor.+--+-- /Note:/ cannot change type.+--+_One :: Prism' (Can a b) a+_One = prism One $ \case+  Non -> Left Non+  One a -> Right a+  Eno b -> Left (Eno b)+  Two a b -> Left (Two a b)++-- | A 'Control.Lens.Prism'' selecting the 'Eno' constructor.+--+-- /Note:/ cannot change type.+--+_Eno :: Prism' (Can a b) b+_Eno = prism Eno $ \case+  Non -> Left Non+  One a -> Left (One a)+  Eno b -> Right b+  Two a b -> Left (Two a b)++-- | A 'Control.Lens.Prism'' selecting the 'Two' constructor.+--+-- /Note:/ cannot change type.+--+_Two :: Prism' (Can a b) (a,b)+_Two = prism (uncurry Two) $ \case+  Non -> Left Non+  One a -> Left (One a)+  Eno b -> Left (Eno b)+  Two a b -> Right (a,b)++-- ------------------------------------------------------------------- --+-- Orphans++instance Swapped Can where+  swapped = iso swapCan swapCan++instance (a ~ a', b ~ b') => Each (Can a a') (Can b b') a b where+  each _ Non = pure Non+  each f (One a) = One <$> f a+  each f (Eno a) = Eno <$> f a+  each f (Two a b) = Two <$> f a <*> f b
+ src/Data/Smash/Lens.hs view
@@ -0,0 +1,91 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- |+-- Module       : Data.Smash.Lens+-- Copyright 	: (c) 2020 Emily Pillmore+-- License	: BSD-style+--+-- Maintainer	: Emily Pillmore <emilypi@cohomolo.gy>+-- Stability	: Experimental+-- Portability	: FlexibleInstances, MPTC, Type Families, UndecideableInstances+--+-- 'Prism's and 'Traversal's for the 'Smash' datatype.+--+module Data.Smash.Lens+( -- * Prisms+  _Nada+, _Smash+   -- * Traversals+, smashed+, smashing+) where+++import Control.Lens++import Data.Smash++-- ------------------------------------------------------------------- --+-- Traversals++-- | A 'Control.Lens.Traversal' of the smashed pair, suitable for use+-- with "Control.Lens".+--+-- >>> over smashed show (Smash 1 2)+-- "(1,2)"+--+-- >>> over smashed show Nada+-- Nada+--+smashed :: Traversal (Smash a b) (Smash c d) (a,b) (c,d)+smashed f = \case+  Nada -> pure Nada+  Smash a b -> uncurry Smash <$> f (a,b)++-- | A 'Control.Lens.Traversal' of the smashed pair, suitable for use+-- with "Control.Lens".+--+-- >>> over smashing show (Smash 1 2)+-- Smash "1" "2"+--+-- >>> over smashing show Nada+-- Nada+--+smashing :: Traversal (Smash a a) (Smash b b) a b+smashing = smashed . both++-- ------------------------------------------------------------------- --+-- Prisms++-- | A 'Control.Lens.Prism'' selecting the 'Nada' constructor.+--+-- /Note:/ cannot change type.+--+_Nada :: Prism' (Smash a b) ()+_Nada = prism (const Nada) $ \case+  Nada -> Right ()+  Smash a b -> Left (Smash a b)++-- | A 'Control.Lens.Prism'' selecting the 'Smash' constructor.+--+-- /Note:/ cannot change type.+--+_Smash :: Prism' (Smash a b) (a,b)+_Smash = prism (uncurry Smash) $ \case+  Smash a b -> Right (a,b)+  Nada -> Left Nada+++-- ------------------------------------------------------------------- --+-- Orphans++instance Swapped Smash where+  swapped = iso swapSmash swapSmash++instance (a ~ a', b ~ b') => Each (Smash a a') (Smash b b') a b where+  each _ Nada = pure Nada+  each f (Smash a b) = Smash <$> f a <*> f b
+ src/Data/Wedge/Lens.hs view
@@ -0,0 +1,108 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- |+-- Module       : Data.Wedge.Lens+-- Copyright 	: (c) 2020 Emily Pillmore+-- License	: BSD-style+--+-- Maintainer	: Emily Pillmore <emilypi@cohomolo.gy>+-- Stability	: Experimental+-- Portability	: FlexibleInstances, MPTC, Type Families, UndecideableInstances+--+-- 'Prism's and 'Traversal's for the 'Wedge' datatype.+--+module Data.Wedge.Lens+( -- * Traversals+  here+, there+  -- * Prisms+, _Nowhere+, _Here+, _There+) where+++import Control.Lens++import Data.Wedge++-- ------------------------------------------------------------------- --+-- Traversals++-- | A 'Control.Lens.Traversal' of the 'Here' case of a 'Wedge',+-- suitable for use with "Control.Lens".+--+-- >>> over here show (Here 1)+-- Here "1"+--+-- >>> over here show (There 'a')+-- There 'a'+--+here :: Traversal' (Wedge a b) a+here f = \case+  Nowhere -> pure Nowhere+  Here a -> Here <$> f a+  There b -> pure (There b)++-- | A 'Control.Lens.Traversal' of the 'There' case of a 'Wedge',+-- suitable for use with "Control.Lens".+--+-- >>> over there show (Here 1)+-- Here 1+--+-- >>> over there show (There 'a')+-- There "'a'"+--+there :: Traversal' (Wedge a b) b+there f = \case+  Nowhere -> pure Nowhere+  Here a -> pure (Here a)+  There b -> There <$> f b++-- ------------------------------------------------------------------- --+-- Prisms++-- | A 'Control.Lens.Prism'' selecting the 'Nowhere' constructor.+--+-- /Note:/ cannot change type.+--+_Nowhere :: Prism' (Wedge a b) ()+_Nowhere = prism (const Nowhere) $ \case+  Nowhere -> Right ()+  Here a -> Left (Here a)+  There b -> Left (There b)++-- | A 'Control.Lens.Prism'' selecting the 'Here' constructor.+--+-- /Note:/ cannot change type.+--+_Here :: Prism (Wedge a b) (Wedge c b) a c+_Here = prism Here $ \case+  Here a -> Right a+  There b -> Left (There b)+  Nowhere -> Left Nowhere++-- | A 'Control.Lens.Prism'' selecting the 'There' constructor.+--+-- /Note:/ cannot change type.+--+_There :: Prism (Wedge a b) (Wedge a d) b d+_There = prism There $ \case+  There b -> Right b+  Here a -> Left (Here a)+  Nowhere -> Left (Nowhere)++-- ------------------------------------------------------------------- --+-- Orphans++instance Swapped Wedge where+  swapped = iso swapWedge swapWedge++instance (a ~ a', b ~ b') => Each (Wedge a a') (Wedge b b') a b where+  each _ Nowhere = pure Nowhere+  each f (Here a) = Here <$> f a+  each f (There a) = There <$> f a
+ test/MyLibTest.hs view
@@ -0,0 +1,4 @@+module Main (main) where++main :: IO ()+main = putStrLn "Test suite not yet implemented."