module Data.Aeson.Extra.Foldable (
ValueF(..),
ObjectF,
ArrayF,
) where
import Prelude ()
import Prelude.Compat
import Data.Aeson.Compat
import Data.Functor.Foldable
import Data.HashMap.Strict (HashMap)
import Data.Data (Data)
import Data.Text (Text)
import Data.Scientific (Scientific)
import Data.Typeable (Typeable)
import Data.Vector (Vector)
import qualified Data.Functor.Foldable as F
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 F.Foldable 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 F.Unfoldable 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