packages feed

microlens-aeson 2.3.0 → 2.3.0.1

raw patch · 7 files changed

+70/−104 lines, 7 filesdep −criteriondep −lensdep −lens-aesondep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies removed: criterion, lens, lens-aeson

Dependency ranges changed: base

API changes (from Hackage documentation)

- Lens.Micro.Aeson: instance Control.DeepSeq.NFData Lens.Micro.Aeson.Primitive

Files

CHANGELOG.md view
@@ -1,3 +1,10 @@+2.3.0.1+-----+- Enable compilation with GHC `7.8` (`base-4.7`). Only when this version of+  `base` is used does our type `Primitive` lose its `Hashable` instance, due to+  a lack of `DeriveAnyClass`. Otherwise, the API is unchanged from+  `microlens-aeson-2.3.0`.+ 2.2.0 ----- - Various fixes to dependency version bounds
− bench/Bench.hs
@@ -1,36 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}--module Main where--import qualified Control.Lens as L-import           Criterion.Main-import qualified Data.Aeson.Lens as AL-import qualified Data.ByteString.Char8 as BS-import qualified Data.ByteString.Lazy.Char8 as BL-import qualified Data.Text as T-import qualified Data.Text.Lazy as TL-import           Lens.Micro-import           Lens.Micro.Aeson-------main :: IO ()-main = defaultMain-  [ bgroup "First elem in Array"-    [ bench "microlens-aeson (String)"  $ nf (^? nth 0 . _Number) ("[1, \"x\"]" :: String)-    , bench "microlens-aeson (T.Text)"  $ nf (^? nth 0 . _Number) ("[1, \"x\"]" :: T.Text)-    , bench "microlens-aeson (TL.Text)" $ nf (^? nth 0 . _Number) ("[1, \"x\"]" :: TL.Text)-    , bench "microlens-aeson (BS)"      $ nf (^? nth 0 . _Number) ("[1, \"x\"]" :: BS.ByteString)-    , bench "microlens-aeson (BL)"      $ nf (^? nth 0 . _Number) ("[1, \"x\"]" :: BL.ByteString)-    , bench "lens-aeson (String)"  $ nf (L.^? AL.nth 0 . AL._Number) ("[1, \"x\"]" :: String)-    , bench "lens-aeson (T.Text)"  $ nf (L.^? AL.nth 0 . AL._Number) ("[1, \"x\"]" :: T.Text)-    , bench "lens-aeson (TL.Text)" $ nf (L.^? AL.nth 0 . AL._Number) ("[1, \"x\"]" :: TL.Text)-    , bench "lens-aeson (BS)"      $ nf (L.^? AL.nth 0 . AL._Number) ("[1, \"x\"]" :: BS.ByteString)-    , bench "lens-aeson (BL)"      $ nf (L.^? AL.nth 0 . AL._Number) ("[1, \"x\"]" :: BL.ByteString) ]-  , bgroup "Getting via `key`"-    [ bench "microlens-aeson (Text)" $ nf (^? key "a")      ("{\"a\": 100, \"b\": 200}" :: T.Text)-    , bench "lens-aeson (Text)"      $ nf (L.^? AL.key "a") ("{\"a\": 100, \"b\": 200}" :: T.Text) ]-  , bgroup "Setting via `key`"-    [ bench "microlens-aeson (Text)" $ nf (& key "a" . _Number %~ (* 10)) ("{\"a\": 100, \"b\": 200}" :: T.Text)-    , bench "lens-aeson (Text)" $ nf (& AL.key "a" . AL._Number L.%~ (* 10)) ("{\"a\": 100, \"b\": 200}" :: T.Text) ]-  ]
lens-aeson.png view

binary file changed (1190547 → 234097 bytes)

microlens-aeson.cabal view
@@ -1,11 +1,13 @@--- This file has been generated from package.yaml by hpack version 0.20.0.+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.31.1. -- -- see: https://github.com/sol/hpack ----- hash: 5c22982c3b1a50a2115914efc79c8e7576f350c249526dc8c1bcd6984e34de77+-- hash: c9fc1021bcd1b90c46c512056ec7718f995cdab18af20c49c265dd1e6615fb7f  name:           microlens-aeson-version:        2.3.0+version:        2.3.0.1 synopsis:       Law-abiding lenses for Aeson, using microlens. description:    Law-abiding lenses for Aeson, using microlens. category:       Numeric@@ -17,14 +19,12 @@ license:        MIT license-file:   LICENSE build-type:     Simple-cabal-version:  >= 1.10- extra-source-files:     AUTHORS.md+    README.md     CHANGELOG.md-    lens-aeson.png     microlens-aeson.png-    README.md+    lens-aeson.png  source-repository head   type: git@@ -33,11 +33,11 @@ library   hs-source-dirs:       src-  ghc-options: -fwarn-unused-imports -fwarn-unused-binds -fwarn-name-shadowing -fwarn-unused-matches -fwarn-incomplete-patterns -fwarn-incomplete-uni-patterns+  ghc-options: -Wall -fwarn-incomplete-record-updates -fwarn-incomplete-uni-patterns   build-depends:-      aeson >=0.7.0.5 && <1.4+      aeson >=0.7.0.5 && <1.5     , attoparsec >=0.10 && <0.14-    , base >=4.8 && <5+    , base >=4.7 && <5     , bytestring     , deepseq     , hashable@@ -58,10 +58,10 @@   main-is: Test.hs   hs-source-dirs:       test-  ghc-options: -fwarn-unused-imports -fwarn-unused-binds -fwarn-name-shadowing -fwarn-unused-matches -fwarn-incomplete-patterns -fwarn-incomplete-uni-patterns -threaded+  ghc-options: -Wall -fwarn-incomplete-record-updates -fwarn-incomplete-uni-patterns -threaded   build-depends:-      aeson >=0.7.0.5 && <1.4-    , base >=4.8 && <5+      aeson >=0.7.0.5 && <1.5+    , base >=4.7 && <5     , bytestring     , deepseq     , hashable@@ -69,30 +69,6 @@     , microlens-aeson     , tasty >=0.10.1.2     , tasty-hunit >=0.9.2-    , text >=0.11.1.10 && <1.3-    , unordered-containers >=0.2.3 && <0.3-    , vector >=0.9 && <0.13-  other-modules:-      Paths_microlens_aeson-  default-language: Haskell2010--benchmark microlens-aeson-bench-  type: exitcode-stdio-1.0-  main-is: Bench.hs-  hs-source-dirs:-      bench-  ghc-options: -fwarn-unused-imports -fwarn-unused-binds -fwarn-name-shadowing -fwarn-unused-matches -fwarn-incomplete-patterns -fwarn-incomplete-uni-patterns -threaded -O2-  build-depends:-      aeson >=0.7.0.5 && <1.4-    , base >=4.8 && <5-    , bytestring-    , criterion >=1.2 && <1.5-    , deepseq-    , hashable-    , lens >=4.15 && <4.17-    , lens-aeson >=1.0-    , microlens >=0.3 && <0.5-    , microlens-aeson     , text >=0.11.1.10 && <1.3     , unordered-containers >=0.2.3 && <0.3     , vector >=0.9 && <0.13
src/Lens/Micro/Aeson.hs view
@@ -1,8 +1,13 @@-{-# LANGUAGE RankNTypes #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}+{-# LANGUAGE CPP               #-} {-# LANGUAGE DefaultSignatures #-}+{-# LANGUAGE DeriveGeneric     #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE RankNTypes        #-} +#if MIN_VERSION_base(4,8,0)+{-# LANGUAGE DeriveAnyClass    #-}+#endif+ -- | -- Module    :  Lens.Micro.Aeson -- Copyright :  (c) Colin Woodbury 2015 - 2018, (c) Edward Kmett 2013-2014, (c) Paul Wilson 2012@@ -11,10 +16,9 @@ -- -- Traversals for Data.Aeson, based on microlens for minimal dependencies. ----- For basic manipulation of Aeson values, full `Prism` functionality--- isn't necessary. Since all Prisms are inherently Traversals, we provide--- Traversals that mimic the behaviour of the Prisms found in the original--- Data.Aeson.Lens.+-- For basic manipulation of Aeson values, full `Prism` functionality isn't+-- necessary. Since all Prisms are inherently Traversals, we provide Traversals+-- that mimic the behaviour of the Prisms found in the original Data.Aeson.Lens.  module Lens.Micro.Aeson   (@@ -33,13 +37,16 @@   , AsJSON(..)   ) where -import           Control.DeepSeq (NFData)+#if !MIN_VERSION_base(4,8,0)+import           Control.Applicative+import           Data.Traversable (traverse)+#endif import           Data.Aeson+import           Data.Aeson.Parser (value) import           Data.Attoparsec.ByteString.Lazy (maybeResult, parse) import qualified Data.ByteString as Strict import           Data.ByteString.Lazy.Char8 as Lazy import           Data.HashMap.Strict (HashMap)-import           Data.Hashable import           Data.Scientific (Scientific) import qualified Data.Scientific as Scientific import           Data.Text as Text@@ -52,6 +59,10 @@ import           Lens.Micro.Aeson.Internal () import           Prelude +#if MIN_VERSION_base(4,8,0)+import           Data.Hashable+#endif+ ------------------------------------------------------------------------------ -- Scientific Traversals ------------------------------------------------------------------------------@@ -95,7 +106,7 @@  instance AsNumber Value where   _Number f (Number n) = Number <$> f n-  _Number _ v = pure v+  _Number _ v          = pure v   {-# INLINE _Number #-}  instance AsNumber Scientific where@@ -133,11 +144,16 @@   | NumberPrim !Scientific   | BoolPrim !Bool   | NullPrim-  deriving (Eq, Ord, Show, Generic, NFData, Hashable)+#if !MIN_VERSION_base(4,8,0)+  deriving (Eq, Ord, Show, Generic)+#endif+#if MIN_VERSION_base(4,8,0)+  deriving (Eq, Ord, Show, Generic, Hashable)+#endif  instance AsNumber Primitive where   _Number f (NumberPrim n) = NumberPrim <$> f n-  _Number _ p = pure p+  _Number _ p              = pure p   {-# INLINE _Number #-}  -- | Traverse into various JSON primitives.@@ -171,7 +187,7 @@   _String :: Traversal' t Text   _String = _Primitive . trav     where trav f (StringPrim s) = StringPrim <$> f s-          trav _ x = pure x+          trav _ x              = pure x   {-# INLINE _String #-}    -- |@@ -183,7 +199,7 @@   _Bool :: Traversal' t Bool   _Bool = _Primitive . trav     where trav f (BoolPrim b) = BoolPrim <$> f b-          trav _ x = pure x+          trav _ x            = pure x   {-# INLINE _Bool #-}    -- |@@ -195,7 +211,7 @@   _Null :: Traversal' t ()   _Null = _Primitive . trav     where trav f NullPrim = const NullPrim <$> f ()-          trav _ x = pure x+          trav _ x        = pure x   {-# INLINE _Null #-}  -- Helper for the function below.@@ -215,15 +231,15 @@   {-# INLINE _Primitive #-}    _String f (String s) = String <$> f s-  _String _ v = pure v+  _String _ v          = pure v   {-# INLINE _String #-}    _Bool f (Bool b) = Bool <$> f b-  _Bool _ v = pure v+  _Bool _ v        = pure v   {-# INLINE _Bool #-}    _Null f Null = const Null <$> f ()-  _Null _ v = pure v+  _Null _ v    = pure v   {-# INLINE _Null #-}  instance AsPrimitive Strict.ByteString@@ -248,7 +264,7 @@ -- Nothing nonNull :: Traversal' Value Value nonNull _ Null = pure Null-nonNull f v = _Value f v+nonNull f v    = _Value f v {-# INLINE nonNull #-}  ------------------------------------------------------------------------------@@ -269,13 +285,13 @@   _Object :: Traversal' t (HashMap Text Value)   _Object = _Value . trav     where trav f (Object o) = Object <$> f o-          trav _ v = pure v+          trav _ v          = pure v   {-# INLINE _Object #-}    _Array :: Traversal' t (Vector Value)   _Array = _Value . trav     where trav f (Array a) = Array <$> f a-          trav _ v = pure v+          trav _ v         = pure v   {-# INLINE _Array #-}  instance AsValue Value where@@ -375,9 +391,9 @@  instance AsJSON Lazy.ByteString where   _JSON f b = maybe (pure b) (fmap encode . f) v-    where v = maybeResult (parse json b) >>= \x -> case fromJSON x of+    where v = maybeResult (parse value b) >>= \x -> case fromJSON x of             Success x' -> Just x'-            _ -> Nothing+            _          -> Nothing   {-# INLINE _JSON #-}  instance AsJSON String where@@ -395,7 +411,7 @@ instance AsJSON Value where   _JSON f v = case fromJSON v of     Success v' -> toJSON <$> f v'-    _ -> pure v+    _          -> pure v   {-# INLINE _JSON #-}  -- $LazyByteStringTests
src/Lens/Micro/Aeson/Internal.hs view
@@ -1,5 +1,7 @@+{-# LANGUAGE CPP               #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeFamilies      #-}+ {-# OPTIONS_GHC -fno-warn-orphans #-}  -- |@@ -15,6 +17,9 @@  module Lens.Micro.Aeson.Internal where +#if !MIN_VERSION_base(4,8,0)+import Control.Applicative+#endif import Data.Aeson (Value(..)) import Data.HashMap.Lazy as HashMap import Data.Text (Text)
test/Test.hs view
@@ -1,14 +1,12 @@---{-# LANGUAGE OverloadedStrings #-}- module Main where  import           Data.Aeson+import qualified Data.HashMap.Strict as HMS+import qualified Data.Text as T import           Lens.Micro import           Lens.Micro.Aeson import           Test.Tasty import           Test.Tasty.HUnit-import qualified Data.HashMap.Strict as HMS-import qualified Data.Text as T  --- @@ -26,8 +24,8 @@     , testCase "" $ ("42" ^? _Integer) @?= Just 42     ]   , testGroup "Conversion Traversals"-    [ testCase "" $ ("[10]" ^? nth 0 . _Integral) @?= Just 10-    , testCase "" $ ("[10.5]" ^? nth 0 . _Integral) @?= Just 10+    [ testCase "" $ ("[10]" ^? nth 0 . _Integral) @?= Just (10 :: Int)+    , testCase "" $ ("[10.5]" ^? nth 0 . _Integral) @?= Just (10 :: Int)     ]   , testGroup "Nulls and Primitives"     [ testCase "" $ ("[1, \"x\", null, true, false]" ^? nth 0 . _Primitive) @?= Just (NumberPrim 1.0)