diff --git a/CHANGELOG.md b/CHANGELOG.md index 85b3791..596b0f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Revision history for aws-arn +## 0.3.2.0 -- 2024-08-20 + +* Use prisms and isos from `microlens-pro`. + ## 0.3.1.0 -- 2023-03-01 * Add `Network.AWS.ARN.S3` with support for S3 bucket and object ARNs. diff --git a/README.md b/README.md index 6ea8095..526aa17 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,7 @@ add a new resource: `test/Network/AWS/ARN/SomeAWSService/Test.hs` 4. Define a `_Foo` `Prism'` that combines the parsing/unparsing - functions above. Use the local definitions of prisms in - `Network.AWS.ARN.Internal.Lens`: + functions above: ```haskell _Function :: Prism' Text Function diff --git a/aws-arn.cabal b/aws-arn.cabal index f1a0d1a..6ad8e51 100644 --- a/aws-arn.cabal +++ b/aws-arn.cabal @@ -1,6 +1,6 @@ cabal-version: 2.2 name: aws-arn -version: 0.3.1.0 +version: 0.3.2.0 synopsis: Types and optics for manipulating Amazon Resource Names (ARNs) @@ -53,15 +53,15 @@ common deps build-depends: , base >=4.12 && <4.21 , deriving-compat >=0.5.10 && <0.7 + , microlens-pro ^>=0.2 , profunctors >=5.0 && <5.7 , tagged ^>=0.8 - , text ^>=1.2.3 || >=2.0 && <2.1 || ^>=2.1 + , text ^>=1.2.3 || ^>=2.0 || ^>=2.1 library import: opts, deps exposed-modules: Network.AWS.ARN - Network.AWS.ARN.Internal.Lens Network.AWS.ARN.Lambda Network.AWS.ARN.S3 @@ -81,7 +81,7 @@ test-suite spec ghc-options: -threaded build-depends: , aws-arn - , tasty >=1.4.0.2 && <1.5 || ^>=1.5 + , tasty ^>=1.4.0.2 || ^>=1.5 , tasty-hunit ^>=0.10.0.3 build-tool-depends: tasty-discover:tasty-discover >=4.2.2 && <5.1 diff --git a/src/Network/AWS/ARN.hs b/src/Network/AWS/ARN.hs index ab59ccf..6605b91 100644 --- a/src/Network/AWS/ARN.hs +++ b/src/Network/AWS/ARN.hs @@ -64,13 +64,13 @@ import Data.Ord.Deriving (deriveOrd1) import Data.Text (Text) import qualified Data.Text as T import GHC.Generics (Generic, Generic1) -import Network.AWS.ARN.Internal.Lens (Iso', Prism', iso, prism') +import Lens.Micro.Pro (Iso', Prism', iso, prism') import Text.Show.Deriving (deriveShow1) -- $setup -- >>> :set -XOverloadedStrings -- >>> import Data.Function ((&)) --- >>> import Network.AWS.ARN.Internal.Lens (from, ix, (.~), (^.), (^?)) +-- >>> Lens.Micro.Pro (from, ix, (.~), (^.), (^?)) -- | A parsed ARN. Either use the '_ARN' 'Prism'', or the 'parseARN' and -- 'renderARN' functions to convert @'Text' \<-\> 'ARN'@. The diff --git a/src/Network/AWS/ARN/Internal/Lens.hs b/src/Network/AWS/ARN/Internal/Lens.hs deleted file mode 100644 index 23a1562..0000000 --- a/src/Network/AWS/ARN/Internal/Lens.hs +++ /dev/null @@ -1,97 +0,0 @@ -{-# LANGUAGE RankNTypes #-} -{-# LANGUAGE ScopedTypeVariables #-} - --- | --- --- Module : Network.AWS.ARN.Internal.Lens --- Copyright : (C) 2020-2022 Bellroy Pty Ltd --- License : BSD-3-Clause --- Maintainer : Bellroy Tech Team --- Stability : experimental --- --- Reimplement a few lens types and combinators to keep the dependency --- footprint down. -module Network.AWS.ARN.Internal.Lens where - -import Data.Functor.Const (Const (..)) -import Data.Functor.Identity (Identity (..)) -import Data.Monoid (First (..)) -import Data.Profunctor (Profunctor (..)) -import Data.Profunctor.Choice (Choice (..)) -import Data.Tagged (Tagged (..)) - -type Lens' s a = forall f. Functor f => (a -> f a) -> s -> f s - -type Getting r s a = (a -> Const r a) -> s -> Const r s - -type Setter s a = (a -> Identity a) -> s -> Identity s - -set :: Setter s a -> a -> s -> s -set l = over l . const -{-# INLINE set #-} - -(.~) :: Setter s a -> a -> s -> s -(.~) = set - -infixr 4 .~ - -over :: Setter s a -> (a -> a) -> s -> s -over l f = runIdentity . l (Identity . f) -{-# INLINE over #-} - -(^.) :: s -> Getting a s a -> a -s ^. l = getConst $ l Const s - -infixl 8 ^. - -type Prism' s a = - forall p f. (Choice p, Applicative f) => p a (f a) -> p s (f s) - -prism' :: forall s a. (a -> s) -> (s -> Maybe a) -> Prism' s a -prism' inj prj p = dimap prj' inj' $ right' p - where - inj' :: Applicative f => Either s (f a) -> f s - inj' = either pure (fmap inj) - - prj' :: s -> Either s a - prj' s = maybe (Left s) Right $ prj s -{-# INLINE prism' #-} - -preview :: Prism' s a -> s -> Maybe a -preview p s = (getFirst . getConst . ($ s)) $ p (Const . First . Just) -{-# INLINE preview #-} - -review :: Prism' s a -> a -> s -review p = runIdentity . unTagged . p . Tagged . Identity -{-# INLINE review #-} - -(^?) :: s -> Prism' s a -> Maybe a -s ^? p = preview p s -{-# INLINE (^?) #-} - -infixl 8 ^? - -type Traversal' s a = forall f. Applicative f => (a -> f a) -> s -> f s - -ix :: Int -> Traversal' [a] a -ix 0 f (x : xs) = (: xs) <$> f x -ix n f (x : xs) = (x :) <$> ix (n - 1) f xs -ix _ _ [] = pure [] - -type Iso' s a = forall p f. (Profunctor p, Functor f) => p a (f a) -> p s (f s) - -type AnIso' s a = Exchange a a a (Identity a) -> Exchange a a s (Identity s) - -data Exchange a b s t = Exchange (s -> a) (b -> t) - -instance Profunctor (Exchange a b) where - dimap f g (Exchange sa bt) = Exchange (sa . f) (g . bt) - -iso :: (s -> a) -> (a -> s) -> Iso' s a -iso f t = dimap f (fmap t) -{-# INLINE iso #-} - -from :: AnIso' s a -> Iso' a s -from l = iso (runIdentity . t) f - where - Exchange f t = l $ Exchange id Identity diff --git a/src/Network/AWS/ARN/Lambda.hs b/src/Network/AWS/ARN/Lambda.hs index dc90d3e..1e23a32 100644 --- a/src/Network/AWS/ARN/Lambda.hs +++ b/src/Network/AWS/ARN/Lambda.hs @@ -26,11 +26,11 @@ import Data.Maybe (maybeToList) import Data.Text (Text) import qualified Data.Text as T import GHC.Generics (Generic) -import Network.AWS.ARN.Internal.Lens (Prism', prism') +import Lens.Micro.Pro (Prism', prism') -- $setup -- >>> :set -XOverloadedStrings --- >>> import Network.AWS.ARN.Internal.Lens ((^?)) +-- >>> import Lens.Micro.Pro ((^?)) -- | An AWS Lambda function name, and optional alias/version qualifier. -- diff --git a/src/Network/AWS/ARN/S3.hs b/src/Network/AWS/ARN/S3.hs index 980a840..1f73e70 100644 --- a/src/Network/AWS/ARN/S3.hs +++ b/src/Network/AWS/ARN/S3.hs @@ -34,11 +34,11 @@ import Data.Hashable (Hashable) import Data.Text (Text) import qualified Data.Text as T import GHC.Generics (Generic) -import Network.AWS.ARN.Internal.Lens (Prism', prism') +import Lens.Micro.Pro (Prism', prism') -- $setup -- >>> :set -XOverloadedStrings --- >>> import Network.AWS.ARN.Internal.Lens ((^?)) +-- >>> Lens.Micro.Pro ((^?)) -- | An AWS S3 object, made of a bucket and an object key. -- diff --git a/test/Network/AWS/ARN/Lambda/Test.hs b/test/Network/AWS/ARN/Lambda/Test.hs index 75bc843..fcef9fd 100644 --- a/test/Network/AWS/ARN/Lambda/Test.hs +++ b/test/Network/AWS/ARN/Lambda/Test.hs @@ -4,7 +4,7 @@ module Network.AWS.ARN.Lambda.Test where import Data.Text (Text) -import Network.AWS.ARN.Internal.Lens (Lens', set, (^?)) +import Lens.Micro.Pro (Lens', set, (^?)) import Network.AWS.ARN.Lambda import Test.Tasty import Test.Tasty.HUnit diff --git a/test/Network/AWS/ARN/S3/Test.hs b/test/Network/AWS/ARN/S3/Test.hs index 7a7443e..a88d1b4 100644 --- a/test/Network/AWS/ARN/S3/Test.hs +++ b/test/Network/AWS/ARN/S3/Test.hs @@ -4,7 +4,7 @@ module Network.AWS.ARN.S3.Test where import Data.Text (Text) -import Network.AWS.ARN.Internal.Lens (Lens', set, (^?)) +import Lens.Micro.Pro (Lens', set, (^?)) import Network.AWS.ARN.S3 import Test.Tasty import Test.Tasty.HUnit @@ -28,8 +28,8 @@ test_all = set (_Object . rObjectKey) "my/other/object" "bucket-name/my/object" @?= "bucket-name/my/other/object" ] - ] - , testGroup + ], + testGroup "S3 bucket" [ testGroup "parsing" diff --git a/test/Network/AWS/ARN/Test.hs b/test/Network/AWS/ARN/Test.hs index 7ab4e3a..9a5dc75 100644 --- a/test/Network/AWS/ARN/Test.hs +++ b/test/Network/AWS/ARN/Test.hs @@ -5,8 +5,8 @@ module Network.AWS.ARN.Test where import Data.List.NonEmpty (NonEmpty (..)) import Data.Text (Text) +import Lens.Micro.Pro (Lens', over, preview, review) import Network.AWS.ARN -import Network.AWS.ARN.Internal.Lens (Lens', over, preview, review) import Test.Tasty import Test.Tasty.HUnit