{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.Aeson.Extra.Recursive (
ValueF(..),
ObjectF,
ArrayF,
) where
import Prelude ()
import Prelude.Compat
import Data.Aeson
import Data.Data (Data)
import Data.Functor.Foldable
import Data.HashMap.Strict (HashMap)
import Data.Scientific (Scientific)
import Data.Text (Text)
import Data.Typeable (Typeable)
import Data.Vector (Vector)
#if !(MIN_VERSION_recursion_schemes(5,0,0))
#define Recursive F.Foldable
#define Corecursive F.Unfoldable
import qualified Data.Functor.Foldable as F
#endif
type ObjectF a = HashMap Text a
type ArrayF a = Vector a
data ValueF a
= ObjectF (ObjectF a)
| ArrayF !(ArrayF a)
| StringF !Text
| NumberF !Scientific
| BoolF !Bool
| NullF
deriving (ValueF a -> ValueF a -> Bool
(ValueF a -> ValueF a -> Bool)
-> (ValueF a -> ValueF a -> Bool) -> Eq (ValueF a)
forall a. Eq a => ValueF a -> ValueF a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ValueF a -> ValueF a -> Bool
$c/= :: forall a. Eq a => ValueF a -> ValueF a -> Bool
== :: ValueF a -> ValueF a -> Bool
$c== :: forall a. Eq a => ValueF a -> ValueF a -> Bool
Eq, ReadPrec [ValueF a]
ReadPrec (ValueF a)
Int -> ReadS (ValueF a)
ReadS [ValueF a]
(Int -> ReadS (ValueF a))
-> ReadS [ValueF a]
-> ReadPrec (ValueF a)
-> ReadPrec [ValueF a]
-> Read (ValueF a)
forall a. Read a => ReadPrec [ValueF a]
forall a. Read a => ReadPrec (ValueF a)
forall a. Read a => Int -> ReadS (ValueF a)
forall a. Read a => ReadS [ValueF a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ValueF a]
$creadListPrec :: forall a. Read a => ReadPrec [ValueF a]
readPrec :: ReadPrec (ValueF a)
$creadPrec :: forall a. Read a => ReadPrec (ValueF a)
readList :: ReadS [ValueF a]
$creadList :: forall a. Read a => ReadS [ValueF a]
readsPrec :: Int -> ReadS (ValueF a)
$creadsPrec :: forall a. Read a => Int -> ReadS (ValueF a)
Read, Int -> ValueF a -> ShowS
[ValueF a] -> ShowS
ValueF a -> String
(Int -> ValueF a -> ShowS)
-> (ValueF a -> String) -> ([ValueF a] -> ShowS) -> Show (ValueF a)
forall a. Show a => Int -> ValueF a -> ShowS
forall a. Show a => [ValueF a] -> ShowS
forall a. Show a => ValueF a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ValueF a] -> ShowS
$cshowList :: forall a. Show a => [ValueF a] -> ShowS
show :: ValueF a -> String
$cshow :: forall a. Show a => ValueF a -> String
showsPrec :: Int -> ValueF a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> ValueF a -> ShowS
Show, Typeable, Typeable (ValueF a)
DataType
Constr
Typeable (ValueF a)
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ValueF a -> c (ValueF a))
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ValueF a))
-> (ValueF a -> Constr)
-> (ValueF a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ValueF a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (ValueF a)))
-> ((forall b. Data b => b -> b) -> ValueF a -> ValueF a)
-> (forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r)
-> (forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r)
-> (forall u. (forall d. Data d => d -> u) -> ValueF a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> ValueF a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a))
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a))
-> Data (ValueF a)
ValueF a -> DataType
ValueF a -> Constr
(forall d. Data d => c (t d)) -> Maybe (c (ValueF a))
(forall b. Data b => b -> b) -> ValueF a -> ValueF a
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ValueF a -> c (ValueF a)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ValueF a)
forall a. Data a => Typeable (ValueF a)
forall a. Data a => ValueF a -> DataType
forall a. Data a => ValueF a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> ValueF a -> ValueF a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> ValueF a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> ValueF a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ValueF a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ValueF a -> c (ValueF a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ValueF a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ValueF a))
forall a.
Typeable a
-> (forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ValueF a -> u
forall u. (forall d. Data d => d -> u) -> ValueF a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ValueF a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ValueF a -> c (ValueF a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (ValueF a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ValueF a))
$cNullF :: Constr
$cBoolF :: Constr
$cNumberF :: Constr
$cStringF :: Constr
$cArrayF :: Constr
$cObjectF :: Constr
$tValueF :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
gmapMp :: (forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
gmapM :: (forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> ValueF a -> m (ValueF a)
gmapQi :: Int -> (forall d. Data d => d -> u) -> ValueF a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> ValueF a -> u
gmapQ :: (forall d. Data d => d -> u) -> ValueF a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> ValueF a -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ValueF a -> r
gmapT :: (forall b. Data b => b -> b) -> ValueF a -> ValueF a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> ValueF a -> ValueF a
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ValueF a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (ValueF a))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (ValueF a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (ValueF a))
dataTypeOf :: ValueF a -> DataType
$cdataTypeOf :: forall a. Data a => ValueF a -> DataType
toConstr :: ValueF a -> Constr
$ctoConstr :: forall a. Data a => ValueF a -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ValueF a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (ValueF a)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ValueF a -> c (ValueF a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ValueF a -> c (ValueF a)
$cp1Data :: forall a. Data a => Typeable (ValueF a)
Data, a -> ValueF b -> ValueF a
(a -> b) -> ValueF a -> ValueF b
(forall a b. (a -> b) -> ValueF a -> ValueF b)
-> (forall a b. a -> ValueF b -> ValueF a) -> Functor ValueF
forall a b. a -> ValueF b -> ValueF a
forall a b. (a -> b) -> ValueF a -> ValueF b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> ValueF b -> ValueF a
$c<$ :: forall a b. a -> ValueF b -> ValueF a
fmap :: (a -> b) -> ValueF a -> ValueF b
$cfmap :: forall a b. (a -> b) -> ValueF a -> ValueF b
Functor, ValueF a -> Bool
(a -> m) -> ValueF a -> m
(a -> b -> b) -> b -> ValueF a -> b
(forall m. Monoid m => ValueF m -> m)
-> (forall m a. Monoid m => (a -> m) -> ValueF a -> m)
-> (forall m a. Monoid m => (a -> m) -> ValueF a -> m)
-> (forall a b. (a -> b -> b) -> b -> ValueF a -> b)
-> (forall a b. (a -> b -> b) -> b -> ValueF a -> b)
-> (forall b a. (b -> a -> b) -> b -> ValueF a -> b)
-> (forall b a. (b -> a -> b) -> b -> ValueF a -> b)
-> (forall a. (a -> a -> a) -> ValueF a -> a)
-> (forall a. (a -> a -> a) -> ValueF a -> a)
-> (forall a. ValueF a -> [a])
-> (forall a. ValueF a -> Bool)
-> (forall a. ValueF a -> Int)
-> (forall a. Eq a => a -> ValueF a -> Bool)
-> (forall a. Ord a => ValueF a -> a)
-> (forall a. Ord a => ValueF a -> a)
-> (forall a. Num a => ValueF a -> a)
-> (forall a. Num a => ValueF a -> a)
-> Foldable ValueF
forall a. Eq a => a -> ValueF a -> Bool
forall a. Num a => ValueF a -> a
forall a. Ord a => ValueF a -> a
forall m. Monoid m => ValueF m -> m
forall a. ValueF a -> Bool
forall a. ValueF a -> Int
forall a. ValueF a -> [a]
forall a. (a -> a -> a) -> ValueF a -> a
forall m a. Monoid m => (a -> m) -> ValueF a -> m
forall b a. (b -> a -> b) -> b -> ValueF a -> b
forall a b. (a -> b -> b) -> b -> ValueF a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: ValueF a -> a
$cproduct :: forall a. Num a => ValueF a -> a
sum :: ValueF a -> a
$csum :: forall a. Num a => ValueF a -> a
minimum :: ValueF a -> a
$cminimum :: forall a. Ord a => ValueF a -> a
maximum :: ValueF a -> a
$cmaximum :: forall a. Ord a => ValueF a -> a
elem :: a -> ValueF a -> Bool
$celem :: forall a. Eq a => a -> ValueF a -> Bool
length :: ValueF a -> Int
$clength :: forall a. ValueF a -> Int
null :: ValueF a -> Bool
$cnull :: forall a. ValueF a -> Bool
toList :: ValueF a -> [a]
$ctoList :: forall a. ValueF a -> [a]
foldl1 :: (a -> a -> a) -> ValueF a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> ValueF a -> a
foldr1 :: (a -> a -> a) -> ValueF a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> ValueF a -> a
foldl' :: (b -> a -> b) -> b -> ValueF a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> ValueF a -> b
foldl :: (b -> a -> b) -> b -> ValueF a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> ValueF a -> b
foldr' :: (a -> b -> b) -> b -> ValueF a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> ValueF a -> b
foldr :: (a -> b -> b) -> b -> ValueF a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> ValueF a -> b
foldMap' :: (a -> m) -> ValueF a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> ValueF a -> m
foldMap :: (a -> m) -> ValueF a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> ValueF a -> m
fold :: ValueF m -> m
$cfold :: forall m. Monoid m => ValueF m -> m
Prelude.Compat.Foldable, Functor ValueF
Foldable ValueF
Functor ValueF
-> Foldable ValueF
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ValueF a -> f (ValueF b))
-> (forall (f :: * -> *) a.
Applicative f =>
ValueF (f a) -> f (ValueF a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ValueF a -> m (ValueF b))
-> (forall (m :: * -> *) a.
Monad m =>
ValueF (m a) -> m (ValueF a))
-> Traversable ValueF
(a -> f b) -> ValueF a -> f (ValueF b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => ValueF (m a) -> m (ValueF a)
forall (f :: * -> *) a.
Applicative f =>
ValueF (f a) -> f (ValueF a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ValueF a -> m (ValueF b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ValueF a -> f (ValueF b)
sequence :: ValueF (m a) -> m (ValueF a)
$csequence :: forall (m :: * -> *) a. Monad m => ValueF (m a) -> m (ValueF a)
mapM :: (a -> m b) -> ValueF a -> m (ValueF b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> ValueF a -> m (ValueF b)
sequenceA :: ValueF (f a) -> f (ValueF a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
ValueF (f a) -> f (ValueF a)
traverse :: (a -> f b) -> ValueF a -> f (ValueF b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> ValueF a -> f (ValueF b)
$cp2Traversable :: Foldable ValueF
$cp1Traversable :: Functor ValueF
Traversable)
type instance Base Value = ValueF
instance Recursive Value where
project :: Value -> Base Value Value
project (Object Object
o) = Object -> ValueF Value
forall a. ObjectF a -> ValueF a
ObjectF Object
o
project (Array Array
a) = Array -> ValueF Value
forall a. ArrayF a -> ValueF a
ArrayF Array
a
project (String Text
s) = Text -> ValueF Value
forall a. Text -> ValueF a
StringF Text
s
project (Number Scientific
n) = Scientific -> ValueF Value
forall a. Scientific -> ValueF a
NumberF Scientific
n
project (Bool Bool
b) = Bool -> ValueF Value
forall a. Bool -> ValueF a
BoolF Bool
b
project Value
Null = Base Value Value
forall a. ValueF a
NullF
instance Corecursive Value where
embed :: Base Value Value -> Value
embed (ObjectF o) = Object -> Value
Object Object
o
embed (ArrayF a) = Array -> Value
Array Array
a
embed (StringF s) = Text -> Value
String Text
s
embed (NumberF n) = Scientific -> Value
Number Scientific
n
embed (BoolF b) = Bool -> Value
Bool Bool
b
embed Base Value Value
NullF = Value
Null