packages feed

aeson-value-parser 0.16 → 0.17

raw patch · 3 files changed

+18/−7 lines, 3 filesdep +hashablePVP ok

version bump matches the API change (PVP)

Dependencies added: hashable

API changes (from Hackage documentation)

- Aeson.ValueParser: fieldMap :: Value a -> Object (HashMap Text a)
+ Aeson.ValueParser: fieldMap :: (Eq a, Hashable a) => String a -> Value b -> Object (HashMap a b)

Files

aeson-value-parser.cabal view
@@ -1,5 +1,5 @@ name: aeson-value-parser-version: 0.16+version: 0.17 synopsis: API for parsing "aeson" JSON tree into Haskell types description:   A flexible parser DSL of JSON AST produced by the \"aeson\" library@@ -37,6 +37,7 @@     attoparsec >=0.13 && <0.14,     base >=4.9 && <5,     bytestring >=0.10 && <0.12,+    hashable >=1.3 && <2,     mtl >=2.2 && <3,     scientific ==0.3.*,     text ==1.*,
library/Aeson/ValueParser.hs view
@@ -1,7 +1,7 @@ {- Parser DSL for the \"aeson\" model of JSON tree. -The general model of this DSL is about switching between contexts+The general model of this DSL is about switching between contexts. -} module Aeson.ValueParser (@@ -92,6 +92,9 @@     Aeson.Bool _ -> "Unexpected type: bool"     Aeson.Null -> "Unexpected type: null" +runString :: String a -> Text -> Either (Maybe Text) a+runString (String a) b = runExcept (runReaderT a b)+ -- ** Definitions ------------------------- @@ -238,11 +241,14 @@ oneOfFields keys valueParser = asum (fmap (flip field valueParser) keys)  {-# INLINE fieldMap #-}-fieldMap :: Value a -> Object (HashMap Text a)-fieldMap fieldParser = Object $ ReaderT $ HashMap.traverseWithKey mapping where-  mapping key ast = case run fieldParser ast of-    Right parsedField -> return parsedField-    Left error -> lift (throwE (Error.named key error))+fieldMap :: (Eq a, Hashable a) => String a -> Value b -> Object (HashMap a b)+fieldMap keyParser fieldParser = Object $ ReaderT $ fmap HashMap.fromList . traverse mapping . HashMap.toList where+  mapping (keyText, ast) = +    case runString keyParser keyText of+      Right parsedKey -> case run fieldParser ast of+        Right parsedField -> return (parsedKey, parsedField)+        Left error -> lift (throwE (Error.named keyText error))+      Left error -> lift (throwE (maybe mempty Error.message error))  {-# INLINE foldlFields #-} foldlFields :: (state -> Text -> field -> state) -> state -> Value field -> Object state
library/Aeson/ValueParser/Prelude.hs view
@@ -105,6 +105,10 @@ ------------------------- import Data.Scientific as Exports (Scientific) +-- hashable+-------------------------+import Data.Hashable as Exports (Hashable)+  showText :: Show a => a -> Text showText = fromString . show