1
1
module Data.Json.Extended.Signature.Core
2
2
( EJsonF (..)
3
+ , getType
3
4
) where
4
5
5
6
import Prelude
@@ -9,10 +10,11 @@ import Data.Eq1 (class Eq1)
9
10
import Data.Foldable as F
10
11
import Data.HugeNum as HN
11
12
import Data.Int as Int
13
+ import Data.Json.Extended.Type as T
12
14
import Data.List as L
13
15
import Data.Map as Map
14
16
import Data.Ord1 (class Ord1 )
15
- import Data.Tuple as T
17
+ import Data.Tuple ( Tuple )
16
18
17
19
-- | The signature endofunctor for the EJson theory.
18
20
data EJsonF a
@@ -27,7 +29,7 @@ data EJsonF a
27
29
| Interval String
28
30
| ObjectId String
29
31
| Array (Array a )
30
- | Object (Array (T . Tuple a a ))
32
+ | Map (Array (Tuple a a ))
31
33
32
34
instance functorEJsonF ∷ Functor EJsonF where
33
35
map f x =
@@ -43,7 +45,7 @@ instance functorEJsonF ∷ Functor EJsonF where
43
45
Interval i → Interval i
44
46
ObjectId oid → ObjectId oid
45
47
Array xs → Array $ f <$> xs
46
- Object xs → Object $ BF .bimap f f <$> xs
48
+ Map xs → Map $ BF .bimap f f <$> xs
47
49
48
50
instance eq1EJsonF ∷ Eq1 EJsonF where
49
51
eq1 Null Null = true
@@ -59,7 +61,7 @@ instance eq1EJsonF ∷ Eq1 EJsonF where
59
61
eq1 (Interval a) (Interval b) = a == b
60
62
eq1 (ObjectId a) (ObjectId b) = a == b
61
63
eq1 (Array xs) (Array ys) = xs == ys
62
- eq1 (Object xs) (Object ys) =
64
+ eq1 (Map xs) (Map ys) =
63
65
let
64
66
xs' = L .fromFoldable xs
65
67
ys' = L .fromFoldable ys
@@ -73,8 +75,8 @@ instance eq1EJsonF ∷ Eq1 EJsonF where
73
75
isSubobject
74
76
∷ ∀ a b
75
77
. (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 )
78
80
→ Boolean
79
81
isSubobject xs ys =
80
82
F .foldl
@@ -136,11 +138,19 @@ instance ord1EJsonF ∷ Ord1 EJsonF where
136
138
compare1 _ (Array _) = GT
137
139
compare1 (Array _) _ = LT
138
140
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