packages feed

smash-optics 0.1.0.0 → 0.1.0.1

raw patch · 5 files changed

+127/−68 lines, 5 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

- Data.Can.Optics: instance (a Data.Type.Equality.~ a', b Data.Type.Equality.~ b') => Optics.Each.Core.Each (GHC.Maybe.Maybe GHC.Types.Bool) (Data.Can.Can a a') (Data.Can.Can b b') a b
- Data.Smash.Optics: instance (a Data.Type.Equality.~ a', b Data.Type.Equality.~ b') => Optics.Each.Core.Each (GHC.Maybe.Maybe GHC.Types.Bool) (Data.Smash.Smash a a') (Data.Smash.Smash b b') a b
- Data.Wedge.Optics: instance (a Data.Type.Equality.~ a', b Data.Type.Equality.~ b') => Optics.Each.Core.Each (GHC.Maybe.Maybe GHC.Types.Bool) (Data.Wedge.Wedge a a') (Data.Wedge.Wedge b b') a b
+ Data.Can.Optics: _CanIso :: Iso (Can a b) (Can c d) (Maybe a, Maybe b) (Maybe c, Maybe d)
+ Data.Can.Optics: instance (a Data.Type.Equality.~ a', b Data.Type.Equality.~ b') => Optics.Each.Core.Each GHC.Types.Bool (Data.Can.Can a a') (Data.Can.Can b b') a b
+ Data.Smash.Optics: _SmashIso :: Iso (Smash a b) (Smash c d) (Maybe (a, b)) (Maybe (c, d))
+ Data.Smash.Optics: instance (a Data.Type.Equality.~ a', b Data.Type.Equality.~ b') => Optics.Each.Core.Each GHC.Types.Bool (Data.Smash.Smash a a') (Data.Smash.Smash b b') a b
+ Data.Wedge.Optics: _WedgeIso :: Iso (Wedge a b) (Wedge c d) (Maybe (Either a b)) (Maybe (Either c d))
+ Data.Wedge.Optics: instance (a Data.Type.Equality.~ a', b Data.Type.Equality.~ b') => Optics.Each.Core.Each GHC.Types.Bool (Data.Wedge.Wedge a a') (Data.Wedge.Wedge b b') a b
- Data.Can.Optics: enoing :: Traversal (Can a b) (Can a c) b c
+ Data.Can.Optics: enoing :: AffineTraversal (Can a b) (Can a c) b c
- Data.Can.Optics: oneing :: Traversal (Can a c) (Can b c) a b
+ Data.Can.Optics: oneing :: AffineTraversal (Can a c) (Can b c) a b
- Data.Can.Optics: twoed :: Traversal' (Can a b) (a, b)
+ Data.Can.Optics: twoed :: AffineTraversal' (Can a b) (a, b)
- Data.Smash.Optics: smashed :: Traversal (Smash a b) (Smash c d) (a, b) (c, d)
+ Data.Smash.Optics: smashed :: AffineTraversal (Smash a b) (Smash c d) (a, b) (c, d)
- Data.Smash.Optics: smashing :: IxTraversal (Maybe Bool) (Smash a a) (Smash b b) a b
+ Data.Smash.Optics: smashing :: IxTraversal Bool (Smash a a) (Smash b b) a b
- Data.Wedge.Optics: here :: Traversal (Wedge a b) (Wedge a' b) a a'
+ Data.Wedge.Optics: here :: AffineTraversal (Wedge a b) (Wedge a' b) a a'
- Data.Wedge.Optics: there :: Traversal (Wedge a b) (Wedge a b') b b'
+ Data.Wedge.Optics: there :: AffineTraversal (Wedge a b) (Wedge a b') b b'

Files

CHANGELOG.md view
@@ -1,5 +1,12 @@ # Revision history for smash-optics ++## 0.1.0.1++* Add `Iso`s for `Wedge`, `Can`, and `Smash`. [#14](https://github.com/emilypi/smash/pull/14)+* Use `Bool` for all indexed traversals (thanks @arybczak for the suggestion! [#12](https://github.com/emilypi/smash/pull/12))+* Use `AffineTraversal`s where appropriate (courtesy of @arybczak [#10](https://github.com/emilypi/smash/pull/10))+ ## 0.1.0.0  * First version. Released on an unsuspecting Koz
smash-optics.cabal view
@@ -1,6 +1,6 @@ cabal-version:   2.0 name:            smash-optics-version:         0.1.0.0+version:         0.1.0.1 synopsis:        Optics for the `smash` library using `optics-core` description:   Prisms, Traversals, and `optics` combinators for the `smash` library.@@ -20,12 +20,10 @@  tested-with:   GHC ==8.2.2-   || ==8.4.3    || ==8.4.4-   || ==8.6.3    || ==8.6.5-   || ==8.8.3-   || ==8.10.1+   || ==8.8.4+   || ==8.10.2  source-repository head   type:     git
src/Data/Can/Optics.hs view
@@ -16,8 +16,10 @@ -- 'Prism's and 'Traversal's for the 'Can' datatype. -- module Data.Can.Optics-( -- * Prisms-  _Non+( -- * Isos+  _CanIso+  -- * Prisms+, _Non , _One , _Eno , _Two@@ -31,48 +33,65 @@  import Data.Can +import Optics.AffineTraversal import Optics.Each.Core import Optics.Iso import Optics.IxTraversal import Optics.Prism import Optics.Traversal + -- ------------------------------------------------------------------- --+-- Isos++-- | A 'Control.Lens.Iso' between a wedge coproduct and pointed coproduct.+--+_CanIso :: Iso (Can a b) (Can c d) (Maybe a, Maybe b) (Maybe c, Maybe d)+_CanIso = iso f g+  where+    f t = (canFst t, canSnd t)++    g (Nothing, Nothing) = Non+    g (Just a, Nothing) = One a+    g (Nothing, Just b) = Eno b+    g (Just a, Just b) = Two a b++-- ------------------------------------------------------------------- -- -- Traversals --- | A 'Optics.Traversal' of the first parameter, suitable for use+-- | An 'AffineTraversal' 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+oneing :: AffineTraversal (Can a c) (Can b c) a b+oneing = atraversalVL $ \point f -> \case+  Non -> point Non   One a -> One <$> f a-  Eno c -> pure (Eno c)+  Eno c -> point (Eno c)   Two a c -> flip Two c <$> f a --- | A 'Optics.Traversal' of the second parameter, suitable for use+-- | An 'AffineTraversal' 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)+enoing :: AffineTraversal (Can a b) (Can a c) b c+enoing = atraversalVL $ \point f -> \case+  Non -> point Non+  One a -> point (One a)   Eno b -> Eno <$> f b   Two a b -> Two a <$> f b --- | A 'Optics.Traversal' of the pair, suitable for use+-- | An 'AffineTraversal' 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)+twoed :: AffineTraversal' (Can a b) (a,b)+twoed = atraversalVL $ \point f -> \case+  Non -> point Non+  One a -> point (One a)+  Eno b -> point (Eno b)   Two a b -> uncurry Two <$> f (a,b) --- | A 'Optics.Traversal' of the pair ala 'both', suitable for use+-- | A 'Traversal' of the pair ala 'both', suitable for use -- with "Optics". -- twoing :: Traversal (Can a a) (Can b b) a b@@ -85,7 +104,7 @@ -- ------------------------------------------------------------------- -- -- Prisms --- | A 'Optics.Prism'' selecting the 'Non' constructor.+-- | A 'Prism'' selecting the 'Non' constructor. -- -- /Note:/ cannot change type. --@@ -96,7 +115,7 @@   Eno b -> Left (Eno b)   Two a b -> Left (Two a b) --- | A 'Optics.Prism'' selecting the 'One' constructor.+-- | A 'Prism'' selecting the 'One' constructor. -- -- /Note:/ cannot change type. --@@ -107,7 +126,7 @@   Eno b -> Left (Eno b)   Two a b -> Left (Two a b) --- | A 'Optics.Prism'' selecting the 'Eno' constructor.+-- | A 'Prism'' selecting the 'Eno' constructor. -- -- /Note:/ cannot change type. --@@ -118,7 +137,7 @@   Eno b -> Right b   Two a b -> Left (Two a b) --- | A 'Optics.Prism'' selecting the 'Two' constructor.+-- | A 'Prism'' selecting the 'Two' constructor. -- -- /Note:/ cannot change type. --@@ -135,9 +154,9 @@ 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+instance (a ~ a', b ~ b') => Each 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+    One a -> One <$> f True a+    Eno a -> Eno <$> f False a+    Two a b -> Two <$> f True a <*> f False b
src/Data/Smash/Optics.hs view
@@ -16,8 +16,10 @@ -- 'Prism's and 'Traversal's for the 'Smash' datatype. -- module Data.Smash.Optics-( -- * Prisms-  _Nada+( -- * Isos+  _SmashIso+-- * Prisms+, _Nada , _Smash    -- * Traversals , smashed@@ -25,33 +27,48 @@ ) where  +import Optics.AffineTraversal import Optics.Each.Core import Optics.Iso import Optics.IxTraversal import Optics.Prism-import Optics.Traversal  import Data.Smash  + -- ------------------------------------------------------------------- --+-- Isos++-- | A 'Control.Lens.Iso' between a smash product and pointed tuple.+--+_SmashIso :: Iso (Smash a b) (Smash c d) (Maybe (a,b)) (Maybe (c,d))+_SmashIso = iso f g+  where+    f Nada = Nothing+    f (Smash a b) = Just (a,b)++    g Nothing = Nada+    g (Just (a,b)) = Smash a b++-- ------------------------------------------------------------------- -- -- Traversals --- | A 'Optics.Traversal' of the smashed pair.+-- | An 'AffineTraversal' of the smashed pair. ----- >>> over smashed show (Smash 1 2)--- "(1,2)"+-- >>> over smashed (fmap pred) (Smash 1 2)+-- Smash 1 1 ----- >>> over smashed show Nada+-- >>> over smashed id Nada -- Nada ---smashed :: Traversal (Smash a b) (Smash c d) (a,b) (c,d)-smashed = traversalVL $ \f -> \case-  Nada -> pure Nada+smashed :: AffineTraversal (Smash a b) (Smash c d) (a,b) (c,d)+smashed = atraversalVL $ \point f -> \case+  Nada -> point Nada   Smash a b -> uncurry Smash <$> f (a,b) --- | A 'Optics.Traversal' of the smashed pair, suitable for use--- with "Control.Optics".+-- | An 'IxTraversal' of the smashed pair. Yes this is equivalent to 'each'.+-- It's here because it's __smashing__. -- -- >>> over smashing show (Smash 1 2) -- Smash "1" "2"@@ -59,15 +76,15 @@ -- >>> over smashing show Nada -- Nada ---smashing :: IxTraversal (Maybe Bool) (Smash a a) (Smash b b) a b+smashing :: IxTraversal 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+  Smash a b -> Smash <$> f True a <*> f False b  -- ------------------------------------------------------------------- -- -- Prisms --- | A 'Optics.Prism'' selecting the 'Nada' constructor.+-- | A 'Prism'' selecting the 'Nada' constructor. -- -- /Note:/ cannot change type. --@@ -76,7 +93,7 @@   Nada -> Right ()   Smash a b -> Left (Smash a b) --- | A 'Optics.Prism'' selecting the 'Smash' constructor.+-- | A 'Prism'' selecting the 'Smash' constructor. -- -- /Note:/ cannot change type. --@@ -92,5 +109,5 @@ 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+instance (a ~ a', b ~ b') => Each Bool (Smash a a') (Smash b b') a b where   each = smashing
src/Data/Wedge/Optics.hs view
@@ -16,8 +16,10 @@ -- 'Prism's and 'Traversal's for the 'Wedge' datatype. -- module Data.Wedge.Optics-( -- * Traversals-  here+( -- * Isos+  _WedgeIso+  -- * Traversals+, here , there   -- * Prisms , _Nowhere@@ -28,17 +30,33 @@  import Data.Wedge +import Optics.AffineTraversal import Optics.Each.Core import Optics.Iso import Optics.IxTraversal import Optics.Prism-import Optics.Traversal   -- ------------------------------------------------------------------- --+-- Isos++-- | A 'Control.Lens.Iso' between a wedge sum and pointed coproduct.+--+_WedgeIso :: Iso (Wedge a b) (Wedge c d) (Maybe (Either a b)) (Maybe (Either c d))+_WedgeIso = iso f g+  where+    f Nowhere = Nothing+    f (Here a) = Just (Left a)+    f (There b) = Just (Right b)++    g Nothing = Nowhere+    g (Just (Left a)) = Here a+    g (Just (Right b)) = There b++-- ------------------------------------------------------------------- -- -- Traversals --- | A 'Optics.Traversal' of the 'Here' case of a 'Wedge',+-- | An 'AffineTraversal' of the 'Here' case of a 'Wedge', -- suitable for use with "Optics". -- -- >>> over here show (Here 1)@@ -47,13 +65,13 @@ -- >>> 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 :: AffineTraversal (Wedge a b) (Wedge a' b) a a'+here = atraversalVL $ \point f -> \case+  Nowhere -> point Nowhere   Here a -> Here <$> f a-  There b -> pure (There b)+  There b -> point (There b) --- | A 'Optics.Traversal' of the 'There' case of a 'Wedge',+-- | An 'AffineTraversal' of the 'There' case of a 'Wedge', -- suitable for use with "Optics". -- -- >>> over there show (Here 1)@@ -62,16 +80,16 @@ -- >>> 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 :: AffineTraversal (Wedge a b) (Wedge a b') b b'+there = atraversalVL $ \point f -> \case+  Nowhere -> point Nowhere+  Here a -> point (Here a)   There b -> There <$> f b  -- ------------------------------------------------------------------- -- -- Prisms --- | A 'Optics.Prism'' selecting the 'Nowhere' constructor.+-- | A 'Prism'' selecting the 'Nowhere' constructor. -- -- /Note:/ this optic cannot change type. --@@ -81,7 +99,7 @@   Here a -> Left (Here a)   There b -> Left (There b) --- | A 'Optics.Prism'' selecting the 'Here' constructor.+-- | A 'Prism'' selecting the 'Here' constructor. -- _Here :: Prism (Wedge a b) (Wedge c b) a c _Here = prism Here $ \case@@ -89,7 +107,7 @@   There b -> Left (There b)   Nowhere -> Left Nowhere --- | A 'Optics.Prism'' selecting the 'There' constructor.+-- | A 'Prism'' selecting the 'There' constructor. -- _There :: Prism (Wedge a b) (Wedge a d) b d _There = prism There $ \case@@ -103,8 +121,8 @@ 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+instance (a ~ a', b ~ b') => Each 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+    Here a -> Here <$> f True a+    There b -> There <$> f False b     Nowhere -> pure Nowhere