Skip to content

Commit

Permalink
aeson-2.0.0.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Oct 9, 2021
1 parent f4c1bc1 commit ff31ca0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# 1.1.1

- Support `aeson-2.0.0.0`: add instances for `KeyMap`.
6 changes: 3 additions & 3 deletions aeson-optics.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
version: 1.1.0.1
x-revision: 6
version: 1.1.1
name: aeson-optics
category: Data, JSON, Optics
license: MIT
Expand All @@ -24,6 +23,7 @@ description: Law-abiding optics for aeson.
extra-source-files:
AUTHORS.markdown
README.markdown
CHANGELOG.md

source-repository head
type: git
Expand All @@ -32,7 +32,7 @@ source-repository head
library
default-language: Haskell2010
build-depends:
aeson >=0.11 && <1.6
aeson >=0.11 && <1.6 || >=2.0 && <2.1
, attoparsec >=0.13.1.0 && <0.15
, base >=4.9 && <4.16
, base-compat >=0.9.3 && <0.13
Expand Down
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
packages: .

source-repository-package
type: git
location: [email protected]:haskell/aeson.git
tag: c1359a2083b8cf7999cf6103aa613d2dc174a76b
30 changes: 29 additions & 1 deletion src/Data/Aeson/Optics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ import qualified Data.Text.Encoding as StrictText
import qualified Data.Text.Lazy as LazyText
import qualified Data.Text.Lazy.Encoding as LazyText

#if MIN_VERSION_aeson(2,0,0)
import qualified Data.Aeson.Key as Key
import qualified Data.Aeson.KeyMap as KM
#endif

-- $setup
-- >>> import Data.ByteString.Char8 as Strict.Char8
-- >>> import qualified Data.Vector as Vector
Expand Down Expand Up @@ -299,7 +304,15 @@ class AsPrimitive t => AsValue t where
-- >>> _Object # HashMap.fromList [("key", _String # "value")] :: String
-- "{\"key\":\"value\"}"
_Object :: Prism' t (HashMap Text Value)
_Object = _Value%prism Object (\v -> case v of Object o -> Right o; _ -> Left v)
_Object = _Value%prism (Object . fwd) (\v -> case v of Object o -> Right (bwd o); _ -> Left v)
where
#if MIN_VERSION_aeson(2,0,0)
fwd = KM.fromHashMapText
bwd = KM.toHashMapText
#else
fwd = id
bwd = id
#endif
{-# INLINE _Object #-}

-- |
Expand Down Expand Up @@ -482,6 +495,21 @@ instance Plated Value where
{-# INLINE plate #-}
-}

#if MIN_VERSION_aeson(2,0,0)
type instance Index (KM.KeyMap v) = Key.Key
type instance IxValue (KM.KeyMap v) = v

instance Ixed (KM.KeyMap v)

instance At (KM.KeyMap v) where
at i = lensVL (\f -> KM.alterF f i)
{-# INLINE at #-}

instance Each Key.Key (KM.KeyMap a) (KM.KeyMap b) a b where
each = itraversalVL KM.traverseWithKey
{-# INLINE[1] each #-}
#endif

------------------------------------------------------------------------------
-- Pattern Synonyms
------------------------------------------------------------------------------
Expand Down

0 comments on commit ff31ca0

Please sign in to comment.