base16-lens 0.1.2.0 → 0.1.3.0
raw patch · 10 files changed
+298/−61 lines, 10 filesdep +text-shortdep ~base16dep ~bytestringdep ~textPVP ok
version bump matches the API change (PVP)
Dependencies added: text-short
Dependency ranges changed: base16, bytestring, text
API changes (from Hackage documentation)
+ Data.ByteString.Short.Base16.Lens: _Base16 :: Prism' ShortByteString ShortByteString
+ Data.ByteString.Short.Base16.Lens: _Base16Lenient :: Iso' ShortByteString ShortByteString
+ Data.ByteString.Short.Base16.Lens: _Hex :: Prism' ShortByteString ShortByteString
+ Data.ByteString.Short.Base16.Lens: pattern Base16 :: ShortByteString -> ShortByteString
+ Data.ByteString.Short.Base16.Lens: pattern Base16Lenient :: ShortByteString -> ShortByteString
+ Data.ByteString.Short.Base16.Lens: pattern Hex :: ShortByteString -> ShortByteString
+ Data.Text.Encoding.Base16.Error.Lens: _ConversionError :: forall err. Prism' (Base16Error err) err
+ Data.Text.Encoding.Base16.Error.Lens: _DecodeError :: forall err. Prism' (Base16Error err) Text
+ Data.Text.Short.Encoding.Base16.Lens: _Base16 :: Prism' ShortText ShortText
+ Data.Text.Short.Encoding.Base16.Lens: _Base16Lenient :: Iso' ShortText ShortText
+ Data.Text.Short.Encoding.Base16.Lens: _Hex :: Prism' ShortText ShortText
+ Data.Text.Short.Encoding.Base16.Lens: pattern Base16 :: ShortText -> ShortText
+ Data.Text.Short.Encoding.Base16.Lens: pattern Base16Lenient :: ShortText -> ShortText
+ Data.Text.Short.Encoding.Base16.Lens: pattern Hex :: ShortText -> ShortText
Files
- CHANGELOG.md +6/−0
- README.md +0/−34
- base16-lens.cabal +12/−8
- src/Data/ByteString/Base16/Lens.hs +6/−4
- src/Data/ByteString/Lazy/Base16/Lens.hs +6/−4
- src/Data/ByteString/Short/Base16/Lens.hs +108/−0
- src/Data/Text/Encoding/Base16/Error/Lens.hs +40/−0
- src/Data/Text/Encoding/Base16/Lens.hs +7/−5
- src/Data/Text/Lazy/Encoding/Base16/Lens.hs +8/−6
- src/Data/Text/Short/Encoding/Base16/Lens.hs +105/−0
CHANGELOG.md view
@@ -1,5 +1,11 @@ # Revision history for base64-lens +## 0.1.3.0++* Bugfix - `_Base16Lenient` pattern now correctly matches and unmatches on unencoded data.+* Bumped `base16` lower bound to meet final stable api+* Added support for `Short` and `Lazy` variants, as well as prisms for `Base16Error`.+ ## 0.1.2.0 * Add lenient isos and patterns
README.md view
@@ -4,37 +4,3 @@ [](https://hackage.haskell.org/package/base16-lens) This package provides optics and convenient pattern synonyms for the [base16](https://hackage.haskell.org/package/base16) library.--### Patterns--The pattern synonyms provided in this library are:--```haskell-pattern Hex :: ByteString -> ByteString-pattern Base16 :: ByteString -> ByteString-pattern Base16Lenient :: ByteString -> ByteString--- and-pattern Hex :: Text -> Text-pattern Base16 :: Text -> Text-pattern Base16Lenient :: Text -> Text-```--These provide a convenient high level interface for passing Base16 encoded values.---### Optics--`Prism`s for encoding and decoding `Text` and `ByteString` values are given as part of the library:---```haskell-_Hex :: Prism' ByteString ByteString-_Base16 :: Prism' ByteString ByteString-_Base16Lenient :: Iso' ByteString ByteString--- and-_Hex:: Prism' Text Text-_Base16 :: Prism' Text Text-_Base16Lenient :: Iso' Text Text-```--If a particular structure has a `Lens` into some `Text` or `ByteString` value they might want to encode (or decode), then composing such a `Lens` with these `Prisms` yields an affine `Traversal`, resulting in a structure which has the focus of its `Lens` encoded as or decoded from Base16.
base16-lens.cabal view
@@ -1,6 +1,6 @@-cabal-version: 1.24+cabal-version: 2.0 name: base16-lens-version: 0.1.2.0+version: 0.1.3.0 synopsis: Optics for the Base16 library description: Prisms and pattern synonyms for the Base16 library homepage: https://github.com/emilypi/base16-lens@@ -17,7 +17,7 @@ README.md tested-with:- GHC ==8.2.2 || ==8.4.3 || ==8.4.4 || ==8.6.3 || ==8.6.5 || ==8.8.3+ GHC ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.3 || ==8.10.1 source-repository head type: git@@ -33,15 +33,19 @@ exposed-modules: Data.ByteString.Base16.Lens Data.ByteString.Lazy.Base16.Lens+ Data.ByteString.Short.Base16.Lens Data.Text.Encoding.Base16.Lens+ Data.Text.Encoding.Base16.Error.Lens Data.Text.Lazy.Encoding.Base16.Lens+ Data.Text.Short.Encoding.Base16.Lens build-depends:- base >=4.10 && <5- , base16 >=0.2.0 && <0.3- , bytestring >=0.10 && <0.11- , lens >=4.0 && <5- , text >=1.2 && <1.3+ base >=4.10 && <5+ , base16 ^>=0.3+ , bytestring ^>=0.10+ , lens >=4.0 && <5+ , text ^>=1.2+ , text-short ^>=0.1 hs-source-dirs: src default-language: Haskell2010
src/Data/ByteString/Base16/Lens.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE Trustworthy #-} -- |--- Module : Data.Text.Encoding.Base16.Lens--- Copyright : (c) 2019 Emily Pillmore+-- Module : Data.ByteString.Base16.Lens+-- Copyright : (c) 2019-2020 Emily Pillmore -- License : BSD-style -- -- Maintainer : Emily Pillmore <emilypi@cohomolo.gy>@@ -104,5 +105,6 @@ -- Base16-encoded 'ByteString' values. -- pattern Base16Lenient :: ByteString -> ByteString-pattern Base16Lenient a <- (view (from _Base16Lenient) -> a) where- Base16Lenient a = view _Base16 a+pattern Base16Lenient a <- (view _Base16Lenient -> a) where+ Base16Lenient a = _Base16Lenient # a+{-# COMPLETE Base16Lenient #-}
src/Data/ByteString/Lazy/Base16/Lens.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE Trustworthy #-} -- |--- Module : Data.Text.Encoding.Base16.Lens--- Copyright : (c) 2019 Emily Pillmore+-- Module : Data.ByteString.Lazy.Base16.Lens+-- Copyright : (c) 2019-2020 Emily Pillmore -- License : BSD-style -- -- Maintainer : Emily Pillmore <emilypi@cohomolo.gy>@@ -102,5 +103,6 @@ -- | Bidirectional pattern synonym for Base16-encoded 'ByteString' values. -- pattern Base16Lenient :: ByteString -> ByteString-pattern Base16Lenient a <- (view (from _Base16Lenient) -> a) where- Base16Lenient a = view _Base16 a+pattern Base16Lenient a <- (view _Base16Lenient -> a) where+ Base16Lenient a = _Base16Lenient # a+{-# COMPLETE Base16Lenient #-}
+ src/Data/ByteString/Short/Base16/Lens.hs view
@@ -0,0 +1,108 @@+{-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE Trustworthy #-}+-- |+-- Module : Data.ByteString.Short.Base16.Lens+-- Copyright : (c) 2019-2020 Emily Pillmore+-- License : BSD-style+--+-- Maintainer : Emily Pillmore <emilypi@cohomolo.gy>+-- Stability : Experimental+-- Portability : non-portable+--+-- This module contains 'Prism''s and 'Iso''s for Base16-encoding and+-- decoding 'ShortByteString' values.+--+module Data.ByteString.Short.Base16.Lens+( -- * Prisms+ _Hex+, _Base16+ -- * Isos+, _Base16Lenient+ -- * Patterns+, pattern Hex+, pattern Base16+, pattern Base16Lenient+) where+++import Control.Lens++import Data.ByteString.Short (ShortByteString)+import qualified Data.ByteString.Short.Base16 as B16S+++-- $setup+--+-- >>> import Control.Lens+-- >>> import Data.ByteString.Short.Base16.Lens+--+-- >>> :set -XOverloadedStrings+-- >>> :set -XTypeApplications+++-- -------------------------------------------------------------------------- --+-- Optics++-- | A 'Prism'' into the Base16 encoding of a 'ShortByteString' value.+--+-- >>> _Base16 # "Sun"+-- "53756e"+--+-- >>> "53756e" ^? _Base16+-- Just "Sun"+--+_Base16 :: Prism' ShortByteString ShortByteString+_Base16 = prism' B16S.encodeBase16' $ \s -> case B16S.decodeBase16 s of+ Left _ -> Nothing+ Right a -> Just a+{-# INLINE _Base16 #-}++-- | A 'Prism'' into the Base16 encoding of a lazy 'ShortByteString' value. This function+-- is an alias of '_Base16'.+--+-- >>> _Hex # "Sun"+-- "53756e"+--+-- >>> "53756e" ^? _Hex+-- Just "Sun"+--+_Hex :: Prism' ShortByteString ShortByteString+_Hex = prism' B16S.encodeBase16' $ \s -> case B16S.decodeBase16 s of+ Left _ -> Nothing+ Right a -> Just a+{-# INLINE _Hex #-}++-- | A 'Iso'' into the Base16 encoding of a leniently decoded 'ShortByteString' value.+--+-- >>> _Base16Lenient # "Sun"+-- "53756e"+--+-- >>> "53756e" ^. _Base16+-- "Sun"+--+_Base16Lenient :: Iso' ShortByteString ShortByteString+_Base16Lenient = iso B16S.decodeBase16Lenient B16S.encodeBase16'+{-# INLINE _Base16Lenient #-}++-- -------------------------------------------------------------------------- --+-- Patterns++-- | Bidirectional pattern synonym for Base16-encoded lazy 'ShortByteString' values.+--+pattern Hex :: ShortByteString -> ShortByteString+pattern Hex a <- (preview _Hex -> Just a) where+ Hex a = _Hex # a++-- | Bidirectional pattern synonym for Base16-encoded lazy 'ShortByteString' values.+--+pattern Base16 :: ShortByteString -> ShortByteString+pattern Base16 a <- (preview _Base16 -> Just a) where+ Base16 a = _Base16 # a++-- | Bidirectional pattern synonym for Base16-encoded 'ShortByteString' values.+--+pattern Base16Lenient :: ShortByteString -> ShortByteString+pattern Base16Lenient a <- (view _Base16Lenient -> a) where+ Base16Lenient a = _Base16Lenient # a+{-# COMPLETE Base16Lenient #-}
+ src/Data/Text/Encoding/Base16/Error/Lens.hs view
@@ -0,0 +1,40 @@+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE Trustworthy #-}+-- |+-- Module : Data.Text.Encoding.Base16.Error.Lens+-- Copyright : (c) 2019-2020 Emily Pillmore+-- License : BSD-style+--+-- Maintainer : Emily Pillmore <emilypi@cohomolo.gy>+-- Stability : Experimental+-- Portability : non-portable+--+-- This module contains 'Prism''s for the `Data.Text.Encoding.Base16.Error.Base16Error`+-- datatype.+--+module Data.Text.Encoding.Base16.Error.Lens+( -- * Prisms+ _DecodeError+, _ConversionError+) where+++import Control.Lens++import Data.Text (Text)+import Data.Text.Encoding.Base16.Error (Base16Error(..))+++-- | A 'Prism'' into the 'DecodeError' case of a 'Base16Error'+--+_DecodeError :: forall err. Prism' (Base16Error err) Text+_DecodeError = prism' DecodeError $ \e -> case e of+ DecodeError t -> Just t+ ConversionError{} -> Nothing++-- | A 'Prism'' into the 'ConversionError' case of a 'Base16Error'+--+_ConversionError :: forall err. Prism' (Base16Error err) err+_ConversionError = prism' ConversionError $ \e -> case e of+ ConversionError err -> Just err+ DecodeError{} -> Nothing
src/Data/Text/Encoding/Base16/Lens.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE Trustworthy #-} -- | -- Module : Data.Text.Encoding.Base16.Lens--- Copyright : (c) 2020 Emily Pillmore+-- Copyright : (c) 2019-2020 Emily Pillmore -- License : BSD-style -- -- Maintainer : Emily Pillmore <emilypi@cohomolo.gy>@@ -69,7 +70,7 @@ Right a -> Just a {-# INLINE _Hex #-} --- | A 'Iso'' into the Base16 encoding of a 'ByteString' value+-- | A 'Iso'' into the Base16 encoding of a 'Text' value -- -- >>> _Base16Lenient # "Sun" -- "53756e"@@ -97,8 +98,9 @@ Base16 a = _Base16 # a -- | Bidirectional pattern synonym for leniently decoded,--- Base16-encoded 'ByteString' values.+-- Base16-encoded 'Text' values. -- pattern Base16Lenient :: Text -> Text-pattern Base16Lenient a <- (view (from _Base16Lenient) -> a) where- Base16Lenient a = view _Base16 a+pattern Base16Lenient a <- (view _Base16Lenient -> a) where+ Base16Lenient a = _Base16Lenient # a+{-# COMPLETE Base16Lenient #-}
src/Data/Text/Lazy/Encoding/Base16/Lens.hs view
@@ -1,8 +1,9 @@ {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE Trustworthy #-} -- |--- Module : Data.Text.Encoding.Base16.Lens--- Copyright : (c) 2020 Emily Pillmore+-- Module : Data.Text.Lazy.Encoding.Base16.Lens+-- Copyright : (c) 2019-2020 Emily Pillmore -- License : BSD-style -- -- Maintainer : Emily Pillmore <emilypi@cohomolo.gy>@@ -71,7 +72,7 @@ {-# INLINE _Hex #-} -- | A 'Iso'' into the Base16 encoding of a leniently decoded--- 'ByteString' value.+-- 'Text' value. -- -- >>> _Base16Lenient # "Sun" -- "53756e"@@ -99,8 +100,9 @@ Base16 a = _Base16 # a -- | Bidirectional pattern synonym for leniently decoded,--- Base16-encoded 'ByteString' values.+-- Base16-encoded 'Text' values. -- pattern Base16Lenient :: Text -> Text-pattern Base16Lenient a <- (view (from _Base16Lenient) -> a) where- Base16Lenient a = view _Base16 a+pattern Base16Lenient a <- (view _Base16Lenient -> a) where+ Base16Lenient a = _Base16Lenient # a+{-# COMPLETE Base16Lenient #-}
+ src/Data/Text/Short/Encoding/Base16/Lens.hs view
@@ -0,0 +1,105 @@+{-# LANGUAGE PatternSynonyms #-}+{-# LANGUAGE ViewPatterns #-}+{-# LANGUAGE Trustworthy #-}+-- |+-- Module : Data.Text.Short.Encoding.Base16.Lens+-- Copyright : (c) 2019-2020 Emily Pillmore+-- License : BSD-style+--+-- Maintainer : Emily Pillmore <emilypi@cohomolo.gy>+-- Stability : Experimental+-- Portability : non-portable+--+-- This module contains 'Prism''s and 'Iso''s Base16-encoding and+-- decoding 'ShortText' values.+--+module Data.Text.Short.Encoding.Base16.Lens+( -- * Prisms+ _Hex+, _Base16+, _Base16Lenient+ -- * Patterns+, pattern Hex+, pattern Base16+, pattern Base16Lenient+) where++import Control.Lens++import Data.Text.Short (ShortText)+import qualified Data.Text.Short.Encoding.Base16 as B16TS++-- $setup+--+-- >>> import Control.Lens+-- >>> import Data.Text.Short.Encoding.Base16.Lens+--+-- >>> :set -XOverloadedStrings+-- >>> :set -XTypeApplications++-- -------------------------------------------------------------------------- --+-- Optics++-- | A 'Prism'' into the Base16 encoding of a 'ShortText' value+--+-- >>> _Base16 # "Sun"+-- "53756e"+--+-- >>> "53756e" ^? _Base16+-- Just "Sun"+--+_Base16 :: Prism' ShortText ShortText+_Base16 = prism' B16TS.encodeBase16 $ \s -> case B16TS.decodeBase16 s of+ Left _ -> Nothing+ Right a -> Just a+{-# INLINE _Base16 #-}++-- | A 'Prism'' into the Base16 encoding of a 'ShortText' value. This is an+-- alias for '_Base16'.+--+-- >>> _Hex # "Sun"+-- "53756e"+--+-- >>> "53756e" ^? _Hex+-- Just "Sun"+--+_Hex :: Prism' ShortText ShortText+_Hex = prism' B16TS.encodeBase16 $ \s -> case B16TS.decodeBase16 s of+ Left _ -> Nothing+ Right a -> Just a+{-# INLINE _Hex #-}++-- | A 'Iso'' into the Base16 encoding of a 'ShortText' value+--+-- >>> _Base16Lenient # "Sun"+-- "53756e"+--+-- >>> "53756e" ^. _Base16Lenient+-- "Sun"+--+_Base16Lenient :: Iso' ShortText ShortText+_Base16Lenient = iso B16TS.decodeBase16Lenient B16TS.encodeBase16+{-# INLINE _Base16Lenient #-}++-- -------------------------------------------------------------------------- --+-- Patterns++-- | Bidirectional pattern synonym for Base16-encoded 'ShortText' values.+--+pattern Hex :: ShortText -> ShortText+pattern Hex a <- (preview _Hex -> Just a) where+ Hex a = _Hex # a++-- | Bidirectional pattern synonym for Base16-encoded 'ShortText' values.+--+pattern Base16 :: ShortText -> ShortText+pattern Base16 a <- (preview _Base16 -> Just a) where+ Base16 a = _Base16 # a++-- | Bidirectional pattern synonym for leniently decoded,+-- Base16-encoded 'ShortText' values.+--+pattern Base16Lenient :: ShortText -> ShortText+pattern Base16Lenient a <- (view _Base16Lenient -> a) where+ Base16Lenient a = _Base16Lenient # a+{-# COMPLETE Base16Lenient #-}