11module Data.Json.Extended.Signature.Core
22 ( EJsonF (..)
3+ , getType
34 ) where
45
56import Prelude
@@ -9,10 +10,11 @@ import Data.Eq1 (class Eq1)
910import Data.Foldable as F
1011import Data.HugeNum as HN
1112import Data.Int as Int
13+ import Data.Json.Extended.Type as T
1214import Data.List as L
1315import Data.Map as Map
1416import Data.Ord1 (class Ord1 )
15- import Data.Tuple as T
17+ import Data.Tuple ( Tuple )
1618
1719-- | The signature endofunctor for the EJson theory.
1820data EJsonF a
@@ -27,7 +29,7 @@ data EJsonF a
2729 | Interval String
2830 | ObjectId String
2931 | Array (Array a )
30- | Object (Array (T. Tuple a a ))
32+ | Map (Array (Tuple a a ))
3133
3234instance functorEJsonF ∷ Functor EJsonF where
3335 map f x =
@@ -43,7 +45,7 @@ instance functorEJsonF ∷ Functor EJsonF where
4345 Interval i → Interval i
4446 ObjectId oid → ObjectId oid
4547 Array xs → Array $ f <$> xs
46- Object xs → Object $ BF .bimap f f <$> xs
48+ Map xs → Map $ BF .bimap f f <$> xs
4749
4850instance eq1EJsonF ∷ Eq1 EJsonF where
4951 eq1 Null Null = true
@@ -59,7 +61,7 @@ instance eq1EJsonF ∷ Eq1 EJsonF where
5961 eq1 (Interval a) (Interval b) = a == b
6062 eq1 (ObjectId a) (ObjectId b) = a == b
6163 eq1 (Array xs) (Array ys) = xs == ys
62- eq1 (Object xs) (Object ys) =
64+ eq1 (Map xs) (Map ys) =
6365 let
6466 xs' = L .fromFoldable xs
6567 ys' = L .fromFoldable ys
@@ -73,8 +75,8 @@ instance eq1EJsonF ∷ Eq1 EJsonF where
7375isSubobject
7476 ∷ ∀ a b
7577 . (Eq a , Eq b )
76- ⇒ L.List (T. Tuple a b )
77- → L.List (T. Tuple a b )
78+ ⇒ L.List (Tuple a b )
79+ → L.List (Tuple a b )
7880 → Boolean
7981isSubobject xs ys =
8082 F .foldl
@@ -136,11 +138,19 @@ instance ord1EJsonF ∷ Ord1 EJsonF where
136138 compare1 _ (Array _) = GT
137139 compare1 (Array _) _ = LT
138140
139- compare1 (Object a) (Object b) = compare (pairsToObject a) (pairsToObject b)
140-
141- pairsToObject
142- ∷ ∀ a b
143- . (Ord a )
144- ⇒ Array (T.Tuple a b )
145- → Map.Map a b
146- pairsToObject = Map .fromFoldable
141+ compare1 (Map a) (Map b) = compare (Map .fromFoldable a) (Map .fromFoldable b)
142+
143+ getType ∷ ∀ a . EJsonF a → T.EJsonType
144+ getType = case _ of
145+ Null → T.Null
146+ String _ → T.String
147+ Boolean _ → T.Boolean
148+ Integer _ → T.Integer
149+ Decimal _ → T.Decimal
150+ Timestamp _ → T.Timestamp
151+ Date _ → T.Date
152+ Time _ → T.Time
153+ Interval _ → T.Interval
154+ ObjectId _ → T.ObjectId
155+ Array _ → T.Array
156+ Map _ → T.Map
0 commit comments