{-# 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.Compat
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 (Eq, Read, Show, Typeable, Data, Functor, Prelude.Compat.Foldable, Traversable)
type instance Base Value = ValueF
instance Recursive Value where
project (Object o) = ObjectF o
project (Array a) = ArrayF a
project (String s) = StringF s
project (Number n) = NumberF n
project (Bool b) = BoolF b
project Null = NullF
instance Corecursive Value where
embed (ObjectF o) = Object o
embed (ArrayF a) = Array a
embed (StringF s) = String s
embed (NumberF n) = Number n
embed (BoolF b) = Bool b
embed NullF = Null