registry-aeson 0.2.3.2 → 0.2.3.3
raw patch · 3 files changed
+22/−2 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Data.Registry.Aeson.Decoder: decodeSetOf :: forall a. (Typeable a, Ord a) => Typed (Decoder a -> Decoder (Set a))
+ Data.Registry.Aeson.Decoder: setOfDecoder :: forall a. (Typeable a, Ord a) => Decoder a -> Decoder (Set a)
+ Data.Registry.Aeson.Encoder: encodeSetOf :: forall a. Typeable a => Typed (Encoder a -> Encoder (Set a))
+ Data.Registry.Aeson.Encoder: setOfEncoder :: Encoder a -> Encoder (Set a)
Files
- registry-aeson.cabal +1/−1
- src/Data/Registry/Aeson/Decoder.hs +11/−1
- src/Data/Registry/Aeson/Encoder.hs +10/−0
registry-aeson.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack name: registry-aeson-version: 0.2.3.2+version: 0.2.3.3 synopsis: Aeson encoders / decoders description: This library provides encoders / decoders which can be easily customized for the Aeson format. category: Data
src/Data/Registry/Aeson/Decoder.hs view
@@ -17,14 +17,15 @@ where import Data.Aeson-import Data.Map qualified as M import Data.Aeson.Key qualified as K import Data.Aeson.KeyMap qualified as KM import Data.ByteString.Lazy qualified as BL import Data.List ((\\))+import Data.Map qualified as M import Data.Registry import Data.Registry.Aeson.TH.Decoder import Data.Registry.Aeson.TH.ThOptions+import Data.Set qualified as S import Data.Text qualified as T import Data.Text.Encoding qualified as T import Data.Vector qualified as Vector@@ -126,6 +127,15 @@ tripleOfDecoder (Decoder a) (Decoder b) (Decoder c) = Decoder $ \case Array [oa, ob, oc] -> (,,) <$> a oa <*> b ob <*> c oc _ -> Left . toS $ "not a triple of " <> showType @a <> "," <> showType @b <> "," <> showType @c++-- | Add a Decoder (Set a)+decodeSetOf :: forall a. (Typeable a, Ord a) => Typed (Decoder a -> Decoder (Set a))+decodeSetOf = fun (setOfDecoder @a)++setOfDecoder :: forall a. (Typeable a, Ord a) => Decoder a -> Decoder (Set a)+setOfDecoder (Decoder a) = Decoder $ \case+ Array vs -> S.fromList <$> for (toList vs) a+ _ -> Left . toS $ "not a set of " <> showType @a -- | Add a Decoder [a] to a registry of decoders -- usage: decoders = decodeListOf @a <: otherDecoders
src/Data/Registry/Aeson/Encoder.hs view
@@ -25,6 +25,7 @@ import Data.Registry import Data.Registry.Aeson.TH.Encoder import Data.Registry.Aeson.TH.ThOptions+import Data.Set qualified as S import Data.Vector qualified as V import Protolude hiding (Type, list) import Prelude (String)@@ -101,6 +102,15 @@ Encoder $ \(a, b, c) -> do let (ls1, ls2) = unzip [ea a, eb b, ec c] (array ls1, list identity ls2)++-- | Create an Encoder for a Set a+encodeSetOf :: forall a. (Typeable a) => Typed (Encoder a -> Encoder (Set a))+encodeSetOf = fun (setOfEncoder @a)++setOfEncoder :: Encoder a -> Encoder (Set a)+setOfEncoder (Encoder ea) = Encoder $ \as -> do+ let (ls1, ls2) = unzip (ea <$> S.toList as)+ (array ls1, list identity ls2) -- | Create an Encoder for a list [a] encodeListOf :: forall a. (Typeable a) => Typed (Encoder a -> Encoder [a])