packages feed

hw-json-lens 0.0.0.1 → 0.1.0.0

raw patch · 7 files changed

+75/−239 lines, 7 filesdep −QuickCheckdep −ansi-wl-pprintdep −arraydep ~bytestringdep ~containersdep ~criterionPVP ok

version bump matches the API change (PVP)

Dependencies removed: QuickCheck, ansi-wl-pprint, array, attoparsec, conduit, dlist, hspec, hw-balancedparens, hw-bits, hw-conduit, hw-diagnostics, hw-parser, hw-prim, hw-rankselect, mmap, mono-traversable, parsec, resourcet, text, transformers, unordered-containers, vector

Dependency ranges changed: bytestring, containers, criterion, hw-json, lens, scientific, word8

API changes (from Hackage documentation)

- HaskellWorks.Data.Json.Lens: class AsNumber t where _Number = _Primitive . _Number _Double = _Number . iso toRealFloat realToFrac _Integer = _Number . iso floor fromIntegral
+ HaskellWorks.Data.Json.Lens: class AsNumber t
- HaskellWorks.Data.Json.Lens: class AsNumber t => AsPrimitive t where _Primitive = _Value . _Primitive _String = _Primitive . prism StringPrim (\ v -> case v of { StringPrim s -> Right s _ -> Left v }) _Bool = _Primitive . prism BoolPrim (\ v -> case v of { BoolPrim b -> Right b _ -> Left v }) _Null = _Primitive . prism (const NullPrim) (\ v -> case v of { NullPrim -> Right () _ -> Left v })
+ HaskellWorks.Data.Json.Lens: class AsNumber t => AsPrimitive t
- HaskellWorks.Data.Json.Lens: class AsPrimitive t => AsValue t where _Object = _Value . prism (JsonPartialObject . toList) (\ v -> case v of { JsonPartialObject o -> Right (fromList o) _ -> Left v }) _Array = _Value . prism JsonPartialArray (\ v -> case v of { JsonPartialArray a -> Right a _ -> Left v })
+ HaskellWorks.Data.Json.Lens: class AsPrimitive t => AsValue t

Files

README.md view
@@ -1,5 +1,5 @@-# hw-xml-lens+# hw-json-lens -[![0.0-branch](https://circleci.com/gh/haskell-works/hw-xml-lens/tree/0.0-branch.svg?style=svg)](https://circleci.com/gh/haskell-works/hw-xml-lens/tree/0.0-branch)+[![0.0-branch](https://circleci.com/gh/haskell-works/hw-json-lens/tree/0.0-branch.svg?style=svg)](https://circleci.com/gh/haskell-works/hw-json-lens/tree/0.0-branch) -`hw-xml-lens` provides traversals and prisms for the [HW-JSON](http://hackage.haskell.org/package/hw-json) library's JsonPartialValue type.+`hw-json-lens` provides traversals and prisms for the [HW-JSON](http://hackage.haskell.org/package/hw-json) library's JsonPartialValue type.
hw-json-lens.cabal view
@@ -1,103 +1,59 @@-name:                   hw-json-lens-version:                0.0.0.1-synopsis:               Lens for hw-json-description:            Please see README.md-homepage:               http://github.com/haskell-works/hw-json-lens#readme-license:                MIT-license-file:           LICENSE-author:                 Alexey Raga-maintainer:             alexey.raga@gmail.com-copyright:              2016 Alexey Raga-category:               Data-build-type:             Simple-extra-source-files:     README.md-cabal-version:          >= 1.22--library-  hs-source-dirs:       src-  exposed-modules:      HaskellWorks.Data.Json.Lens, HaskellWorks.Data.ListMap-  build-depends:        base                          >= 4          && < 5-                      , array-                      , ansi-wl-pprint-                      , attoparsec-                      , bytestring-                      , conduit-                      , containers-                      , dlist-                      , hw-balancedparens             >= 0.1.0.0-                      , hw-bits                       >= 0.4.0.0-                      , hw-conduit                    >= 0.1.0.0-                      , hw-diagnostics                >= 0.0.0.5-                      , hw-json                       >= 0.4.0.0-                      , hw-parser-                      , hw-prim                       >= 0.4.0.0-                      , hw-rankselect                 >= 0.8.0.0-                      , lens >=3.8-                      , mmap-                      , mono-traversable-                      , resourcet-                      , scientific-                      , text-                      , unordered-containers-                      , vector-                      , word8+-- This file has been generated from package.yaml by hpack version 0.18.1.+--+-- see: https://github.com/sol/hpack -  default-language:     Haskell2010-  ghc-options:          -Wall -O2 -msse4.2+name:           hw-json-lens+version:        0.1.0.0+synopsis:       Lens for hw-json+description:    Please see README.md+category:       Data+homepage:       http://github.com/haskell-works/hw-json-lens#readme+bug-reports:    https://github.com/haskell-works/hw-json-lens/issues+author:         Alexey Raga, John Ky+maintainer:     alexey.raga@gmail.com, newhoggy@gmail.com+copyright:      2016 Alexey Raga, 2018 John Ky+license:        MIT+license-file:   LICENSE+build-type:     Simple+cabal-version:  >= 1.10 -test-suite hw-json-lens-test-  type:                 exitcode-stdio-1.0-  hs-source-dirs:       test-  main-is:              Spec.hs-  other-modules:        HaskellWorks.Data.Json.NthSpec-                      , HaskellWorks.Data.Json.LensSpec-  build-depends:        base                          >= 4          && < 5-                      , attoparsec-                      , bytestring-                      , containers-                      , conduit-                      , hspec-                      , hw-balancedparens             >= 0.1.0.0-                      , hw-bits                       >= 0.4.0.0-                      , hw-conduit                    >= 0.1.0.0-                      , hw-json                       >= 0.4.0.0-                      , hw-json-lens-                      , hw-prim                       >= 0.4.0.0-                      , hw-rankselect                 >= 0.8.0.0-                      , lens >=3.8-                      , mmap-                      , parsec-                      , QuickCheck-                      , resourcet-                      , scientific-                      , transformers-                      , unordered-containers-                      , vector-  ghc-options:          -threaded -rtsopts -with-rtsopts=-N -Wall-  default-language:     Haskell2010+extra-source-files:+    README.md  source-repository head-  type:     git+  type: git   location: https://github.com/haskell-works/hw-json-lens +library+  hs-source-dirs:+      src+  ghc-options: -Wall -O2 -msse4.2+  build-depends:+      base                  >= 4          && < 5+    , bytestring            >= 0.10       && < 0.11+    , hw-json               >= 0.8.1      && < 0.9+    , lens                  >= 4          && < 5+    , containers          >= 0.5        && < 0.6+    , scientific          >= 0.3        && < 0.4+    , word8               >= 0.1        && < 0.2+  exposed-modules:+      HaskellWorks.Data.Json.Lens+      HaskellWorks.Data.ListMap+  other-modules:+      Paths_hw_json_lens+  default-language: Haskell2010+ benchmark bench-    Type: exitcode-stdio-1.0-    HS-Source-Dirs: bench-    Main-Is: Main.hs-    GHC-Options: -O2 -Wall -msse4.2-    Default-Language: Haskell2010-    Build-Depends:      base                          >= 4          && < 5-                      , bytestring-                      , conduit-                      , criterion-                      , hw-bits                       >= 0.4.0.0-                      , hw-conduit                    >= 0.1.0.0-                      , hw-json-lens-                      , hw-prim                       >= 0.4.0.0-                      , hw-rankselect                 >= 0.8.0.0-                      , lens >=3.8-                      , mmap-                      , resourcet-                      , scientific-                      , unordered-containers-                      , vector+  type: exitcode-stdio-1.0+  main-is: Main.hs+  hs-source-dirs:+      bench+  ghc-options: -Wall -O2 -msse4.2+  build-depends:+      base                  >= 4          && < 5+    , bytestring            >= 0.10       && < 0.11+    , hw-json               >= 0.8.1      && < 0.9+    , lens                  >= 4          && < 5+    , criterion             >= 1.4        && < 1.5+    , hw-json-lens+  default-language: Haskell2010
src/HaskellWorks/Data/Json/Lens.hs view
@@ -8,6 +8,7 @@ {-# LANGUAGE Trustworthy           #-} {-# LANGUAGE TupleSections         #-} {-# LANGUAGE TypeFamilies          #-}+ {-# OPTIONS_GHC -fno-warn-orphans #-}  --------------------------------------------------------------------@@ -21,16 +22,17 @@  module HaskellWorks.Data.Json.Lens where -import           Control.Applicative-import           Control.Lens-import           Data.Data-import           Data.Scientific                     (Scientific)-import qualified Data.Scientific                     as Scientific-import           GHC.Base-import           HaskellWorks.Data.Json.PartialValue as J-import           HaskellWorks.Data.ListMap           (ListMap, fromList, toList)-import           Prelude                             hiding (null)+import Control.Applicative+import Control.Lens+import Data.Data+import Data.Scientific                     (Scientific)+import GHC.Base+import HaskellWorks.Data.Json.PartialValue as J+import HaskellWorks.Data.ListMap           (ListMap, fromList, toList)+import Prelude                             hiding (null) +import qualified Data.Scientific as Scientific+ ------------------------------------------------------------------------------ -- Scientific prisms ------------------------------------------------------------------------------@@ -195,7 +197,7 @@       toPrim (JsonPartialNumber n) = Right $ NumberPrim (Scientific.fromFloatDigits n)       toPrim (JsonPartialBool b)   = Right $ BoolPrim b       toPrim JsonPartialNull       = Right NullPrim-      toPrim v          = Left v+      toPrim v                     = Left v       {-# INLINE toPrim #-}       fromPrim (StringPrim s) = JsonPartialString s       fromPrim (NumberPrim n) = JsonPartialNumber (realToFrac n)@@ -428,11 +430,11 @@ type instance IxValue JsonPartialValue = JsonPartialValue instance Ixed JsonPartialValue where   ix i f (JsonPartialObject o) = (JsonPartialObject . toList) <$> ix i f (fromList o)-  ix _ _ v          = pure v+  ix _ _ v                     = pure v   {-# INLINE ix #-}  instance Plated JsonPartialValue where   plate f (JsonPartialObject o) = (JsonPartialObject . toList) <$> traverse f (fromList o)-  plate f (JsonPartialArray a) = JsonPartialArray <$> traverse f a-  plate _ xs = pure xs+  plate f (JsonPartialArray a)  = JsonPartialArray <$> traverse f a+  plate _ xs                    = pure xs   {-# INLINE plate #-}
src/HaskellWorks/Data/ListMap.hs view
@@ -3,17 +3,17 @@ {-# LANGUAGE FlexibleInstances     #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE RankNTypes            #-}-{-# LANGUAGE Trustworthy           #-} {-# LANGUAGE TupleSections         #-} {-# LANGUAGE TypeFamilies          #-} {-# OPTIONS_GHC -fno-warn-orphans #-}  module HaskellWorks.Data.ListMap where -import           Control.Lens-import           Data.Monoid-import           Prelude      hiding (lookup, null)-import qualified Prelude      as P+import Control.Lens+import Data.Monoid+import Prelude      hiding (lookup, null)++import qualified Prelude as P  newtype ListMap a = ListMap [(String, a)] deriving (Eq, Show) 
− test/HaskellWorks/Data/Json/LensSpec.hs
@@ -1,62 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-module HaskellWorks.Data.Json.LensSpec (spec) where--import           GHC.Base-import           Control.Lens-import qualified Data.ByteString as Strict-import           HaskellWorks.Data.ListMap (fromList)-import qualified Data.Vector.Storable                                       as DVS-import           Data.Word-import           Prelude hiding (null)-import           HaskellWorks.Data.BalancedParens.Simple-import           HaskellWorks.Data.Bits.BitShown-import           HaskellWorks.Data.Json.Succinct.Cursor-import           HaskellWorks.Data.Json.Succinct.PartialIndex-import           HaskellWorks.Data.Json.PartialValue-import           HaskellWorks.Data.Json.Lens-import           HaskellWorks.Data.FromByteString-import           Test.Hspec--{-# ANN module ("HLint: ignore Redundant do"        :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication"  :: String) #-}--loadJson :: Strict.ByteString -> JsonCursor Strict.ByteString (BitShown (DVS.Vector Word64)) (SimpleBalancedParens (DVS.Vector Word64))-loadJson = fromByteString--j :: Strict.ByteString -> JsonPartialValue-j = jsonPartialJsonValueAt . jsonPartialIndexAt . loadJson--spec :: Spec-spec = describe "Nth Spec" $ do-  let json = j "{\"d\": 1.5, \"s\": \"xyz\", \"b\": true, \"n\": null, \"o\": {}}"--  it "key" $ do-    json ^? key "d"             `shouldBe` Just (JsonPartialNumber 1.5)-    j "[1,2,3]" ^? key "s"      `shouldBe` Nothing--  it "key composed" $ do-    json ^? key "d" . _Number   `shouldBe` Just 1.5-    json ^? key "s" . _String   `shouldBe` Just "xyz"-    json ^? key "b" . _Bool     `shouldBe` Just True-    json ^? key "n" . _Null     `shouldBe` Just ()-    json ^? key "b" . _Null     `shouldBe` Nothing--  it "nonNull" $ do-    json ^? key "s" . nonNull   `shouldBe` Just (JsonPartialString "xyz")-    json ^? key "o" . nonNull   `shouldBe` Just (JsonPartialObject [])-    json ^? key "n" . nonNull   `shouldBe` Nothing--  it "preview" $ do-    preview _Value (j "[1,2,3]") `shouldBe` Just (JsonPartialArray [JsonPartialNumber 1.0,JsonPartialNumber 2.0,JsonPartialNumber 3.0])--  it "object" $ do-    json ^? key "o" . _Object   `shouldBe` Just (fromList [])-    json ^? key "n" . _Object   `shouldBe` Nothing--  it "members" $ do-    fromList (json ^@.. members) `shouldBe` fromList [("d", JsonPartialNumber 1.5), ("s", JsonPartialString "xyz"), ("b", JsonPartialBool True), ("n", JsonPartialNull), ("o", JsonPartialObject [])]-    (json & members . _Number *~10) ^? key "d" `shouldBe` Just (JsonPartialNumber 15)--  it "values" $ do-    j "[1,2,3]" ^.. values                  `shouldBe` [JsonPartialNumber 1, JsonPartialNumber 2, JsonPartialNumber 3]-    (j "[1,2,3]" & values . _Number *~ 10)  `shouldBe` JsonPartialArray [JsonPartialNumber 10, JsonPartialNumber 20, JsonPartialNumber 30]
− test/HaskellWorks/Data/Json/NthSpec.hs
@@ -1,59 +0,0 @@-{-# LANGUAGE OverloadedStrings #-}-module HaskellWorks.Data.Json.NthSpec (spec) where--import           GHC.Base-import           Control.Lens-import qualified Data.ByteString as Strict-import qualified Data.Vector.Storable                                       as DVS-import           Data.Word-import           Prelude hiding (null)-import           HaskellWorks.Data.BalancedParens.Simple-import           HaskellWorks.Data.Bits.BitShown-import           HaskellWorks.Data.Json.Succinct.Cursor-import           HaskellWorks.Data.Json.Succinct.PartialIndex-import           HaskellWorks.Data.Json.PartialValue-import           HaskellWorks.Data.Json.Lens-import           HaskellWorks.Data.FromByteString-import           Test.Hspec--{-# ANN module ("HLint: ignore Redundant do"        :: String) #-}-{-# ANN module ("HLint: ignore Reduce duplication"  :: String) #-}--loadJson :: Strict.ByteString -> JsonCursor Strict.ByteString (BitShown (DVS.Vector Word64)) (SimpleBalancedParens (DVS.Vector Word64))-loadJson = fromByteString--j :: Strict.ByteString -> JsonPartialValue-j = jsonPartialJsonValueAt . jsonPartialIndexAt . loadJson--spec :: Spec-spec = describe "Nth Spec" $ do-  let json = j "[1.5, \"x\", null, true, false]"-  it "nth" $ do-    json ^? nth 0 . _Number   `shouldBe` Just 1.5-    json ^? nth 0 . _Double   `shouldBe` Just 1.5-    json ^? nth 0 . _Integer  `shouldBe` Just 1-    json ^? nth 0 . _String   `shouldBe` Nothing--  it "nth with string" $ do-    json ^? nth 1 . _String   `shouldBe` Just "x"-    json ^? nth 1 . _Double   `shouldBe` Nothing--  it "nth out of bound" $ do-    json ^? nth 8 . _Double   `shouldBe` Nothing-    json ^? nth 22 . _String  `shouldBe` Nothing--  it "nth with null" $ do-    json ^? nth 2 . _Null `shouldBe` Just ()-    json ^? nth 3 . _Null `shouldBe` Nothing--  it "nth with bool" $ do-    json ^? nth 3 . _Bool `shouldBe` Just True-    json ^? nth 4 . _Bool `shouldBe` Just False-    json ^? nth 2 . _Bool `shouldBe` Nothing--  it "nth with primitive" $ do-    json ^? nth 0 . _Primitive `shouldBe` Just (NumberPrim 1.5)-    json ^? nth 1 . _Primitive `shouldBe` Just (StringPrim "x")-    json ^? nth 2 . _Primitive `shouldBe` Just NullPrim-    json ^? nth 3 . _Primitive `shouldBe` Just (BoolPrim True)-    json ^? nth 4 . _Primitive `shouldBe` Just (BoolPrim False)
− test/Spec.hs
@@ -1,1 +0,0 @@-{-# OPTIONS_GHC -F -pgmF hspec-discover #-}