smash-optics (empty) → 0.1.0.0
raw patch · 8 files changed
+441/−0 lines, 8 filesdep +basedep +optics-coredep +smashsetup-changed
Dependencies added: base, optics-core, smash
Files
- CHANGELOG.md +5/−0
- LICENSE +30/−0
- README.md +9/−0
- Setup.hs +2/−0
- smash-optics.cabal +46/−0
- src/Data/Can/Optics.hs +143/−0
- src/Data/Smash/Optics.hs +96/−0
- src/Data/Wedge/Optics.hs +110/−0
+ CHANGELOG.md view
@@ -0,0 +1,5 @@+# Revision history for smash-optics++## 0.1.0.0++* First version. Released on an unsuspecting Koz
+ 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-optics: Optics for the smash library+++[](https://travis-ci.com/emilypi/smash)+[](https://hackage.haskell.org/package/smash-optics)++++This library provides optics for the [smash](https://hackage.haskell.org/package/smash) using the `optics` library.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ smash-optics.cabal view
@@ -0,0 +1,46 @@+cabal-version: 2.0+name: smash-optics+version: 0.1.0.0+synopsis: Optics for the `smash` library using `optics-core`+description:+ Prisms, Traversals, and `optics` 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-doc-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.Optics+ Data.Smash.Optics+ Data.Wedge.Optics++ build-depends:+ base >=4.10 && <5.0+ , optics-core ^>=0.3+ , smash ^>=0.1++ hs-source-dirs: src+ default-language: Haskell2010
+ src/Data/Can/Optics.hs view
@@ -0,0 +1,143 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- |+-- Module : Data.Can.Optics+-- 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.Optics+( -- * Prisms+ _Non+, _One+, _Eno+, _Two+ -- * Traversals+, oneing+, enoing+, twoed+, twoing+) where+++import Data.Can++import Optics.Each.Core+import Optics.Iso+import Optics.IxTraversal+import Optics.Prism+import Optics.Traversal++-- ------------------------------------------------------------------- --+-- Traversals++-- | A 'Optics.Traversal' of the first parameter, suitable for use+-- with "Optics".+--+oneing :: Traversal (Can a c) (Can b c) a b+oneing = traversalVL $ \f -> \case+ Non -> pure Non+ One a -> One <$> f a+ Eno c -> pure (Eno c)+ Two a c -> flip Two c <$> f a++-- | A 'Optics.Traversal' of the second parameter, suitable for use+-- with "Optics".+--+enoing :: Traversal (Can a b) (Can a c) b c+enoing = traversalVL $ \f -> \case+ Non -> pure Non+ One a -> pure (One a)+ Eno b -> Eno <$> f b+ Two a b -> Two a <$> f b++-- | A 'Optics.Traversal' of the pair, suitable for use+-- with "Optics".+--+-- /Note:/ cannot change type.+--+twoed :: Traversal' (Can a b) (a,b)+twoed = traversalVL $ \f -> \case+ Non -> pure Non+ One a -> pure (One a)+ Eno b -> pure (Eno b)+ Two a b -> uncurry Two <$> f (a,b)++-- | A 'Optics.Traversal' of the pair ala 'both', suitable for use+-- with "Optics".+--+twoing :: Traversal (Can a a) (Can b b) a b+twoing = traversalVL $ \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 'Optics.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 'Optics.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 'Optics.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 'Optics.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 (Maybe Bool) (Can a a') (Can b b') a b where+ each = itraversalVL $ \f -> \case+ Non -> pure Non+ One a -> One <$> f (Just True) a+ Eno a -> Eno <$> f (Just False) a+ Two a b -> Two <$> f (Just True) a <*> f (Just False) b
+ src/Data/Smash/Optics.hs view
@@ -0,0 +1,96 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- |+-- Module : Data.Smash.Optics+-- 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.Optics+( -- * Prisms+ _Nada+, _Smash+ -- * Traversals+, smashed+, smashing+) where+++import Optics.Each.Core+import Optics.Iso+import Optics.IxTraversal+import Optics.Prism+import Optics.Traversal++import Data.Smash+++-- ------------------------------------------------------------------- --+-- Traversals++-- | A 'Optics.Traversal' of the smashed pair.+--+-- >>> 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 = traversalVL $ \f -> \case+ Nada -> pure Nada+ Smash a b -> uncurry Smash <$> f (a,b)++-- | A 'Optics.Traversal' of the smashed pair, suitable for use+-- with "Control.Optics".+--+-- >>> over smashing show (Smash 1 2)+-- Smash "1" "2"+--+-- >>> over smashing show Nada+-- Nada+--+smashing :: IxTraversal (Maybe Bool) (Smash a a) (Smash b b) a b+smashing = itraversalVL $ \f -> \case+ Nada -> pure Nada+ Smash a b -> Smash <$> f (Just True) a <*> f (Just False) b++-- ------------------------------------------------------------------- --+-- Prisms++-- | A 'Optics.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 'Optics.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 (Maybe Bool) (Smash a a') (Smash b b') a b where+ each = smashing
+ src/Data/Wedge/Optics.hs view
@@ -0,0 +1,110 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE LambdaCase #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+-- |+-- Module : Data.Wedge.Optics+-- 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.Optics+( -- * Traversals+ here+, there+ -- * Prisms+, _Nowhere+, _Here+, _There+) where+++import Data.Wedge++import Optics.Each.Core+import Optics.Iso+import Optics.IxTraversal+import Optics.Prism+import Optics.Traversal+++-- ------------------------------------------------------------------- --+-- Traversals++-- | A 'Optics.Traversal' of the 'Here' case of a 'Wedge',+-- suitable for use with "Optics".+--+-- >>> over here show (Here 1)+-- Here "1"+--+-- >>> over here show (There 'a')+-- There 'a'+--+here :: Traversal (Wedge a b) (Wedge a' b) a a'+here = traversalVL $ \f -> \case+ Nowhere -> pure Nowhere+ Here a -> Here <$> f a+ There b -> pure (There b)++-- | A 'Optics.Traversal' of the 'There' case of a 'Wedge',+-- suitable for use with "Optics".+--+-- >>> over there show (Here 1)+-- Here 1+--+-- >>> over there show (There 'a')+-- There "'a'"+--+there :: Traversal (Wedge a b) (Wedge a b') b b'+there = traversalVL $ \f -> \case+ Nowhere -> pure Nowhere+ Here a -> pure (Here a)+ There b -> There <$> f b++-- ------------------------------------------------------------------- --+-- Prisms++-- | A 'Optics.Prism'' selecting the 'Nowhere' constructor.+--+-- /Note:/ this optic 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 'Optics.Prism'' selecting the 'Here' constructor.+--+_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 'Optics.Prism'' selecting the 'There' constructor.+--+_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 (Maybe Bool) (Wedge a a') (Wedge b b') a b where+ each = itraversalVL $ \f -> \case+ Here a -> Here <$> f (Just True) a+ There b -> There <$> f (Just False) b+ Nowhere -> pure Nowhere