@@ -19,7 +19,7 @@ module Data.Argonaut.JCursor
19
19
import qualified Data.Array as A
20
20
import qualified Data.StrMap as M
21
21
22
- data JCursor = JCursorTop | JField JCursor String | JIndex JCursor Number
22
+ data JCursor = JCursorTop | JField String JCursor | JIndex Number JCursor
23
23
24
24
newtype JsonPrim = JsonPrim (forall a . (JNull -> a) -> (JBoolean -> a) -> (JNumber -> a) -> (JString -> a) -> a )
25
25
@@ -45,26 +45,26 @@ module Data.Argonaut.JCursor
45
45
46
46
insideOut :: JCursor -> JCursor
47
47
insideOut JCursorTop = JCursorTop
48
- insideOut (JField c i ) = downField i (insideOut c )
49
- insideOut (JIndex c i ) = downIndex i (insideOut c )
48
+ insideOut (JField i c ) = downField i (insideOut c )
49
+ insideOut (JIndex i c ) = downIndex i (insideOut c )
50
50
51
51
downField :: String -> JCursor -> JCursor
52
52
downField i = downField' where
53
- downField' JCursorTop = JField JCursorTop i
54
- downField' (JField c i' ) = JField (downField' c ) i'
55
- downField' (JIndex c i' ) = JIndex (downField' c ) i'
53
+ downField' JCursorTop = JField i JCursorTop
54
+ downField' (JField i' c ) = JField i' (downField' c )
55
+ downField' (JIndex i' c ) = JIndex i' (downField' c )
56
56
57
57
downIndex :: Number -> JCursor -> JCursor
58
58
downIndex i = downIndex' where
59
- downIndex' JCursorTop = JIndex JCursorTop i
60
- downIndex' (JField c i' ) = JField (downIndex' c ) i'
61
- downIndex' (JIndex c i' ) = JIndex (downIndex' c ) i'
59
+ downIndex' JCursorTop = JIndex i JCursorTop
60
+ downIndex' (JField i' c ) = JField i' (downIndex' c )
61
+ downIndex' (JIndex i' c ) = JIndex i' (downIndex' c )
62
62
63
63
cursorGet :: JCursor -> Json -> Maybe Json
64
64
cursorGet JCursorTop = Just
65
- cursorGet (JField c i ) = foldJsonObject Nothing g where
65
+ cursorGet (JField i c ) = foldJsonObject Nothing g where
66
66
g m = M. lookup i m >>= cursorGet c
67
- cursorGet (JIndex c i ) = foldJsonArray Nothing g where
67
+ cursorGet (JIndex i c ) = foldJsonArray Nothing g where
68
68
g a = a A. !! i >>= cursorGet c
69
69
70
70
inferEmpty :: JCursor -> Json
@@ -74,10 +74,10 @@ module Data.Argonaut.JCursor
74
74
75
75
cursorSet :: JCursor -> Json -> Json -> Maybe Json
76
76
cursorSet JCursorTop v = Just <<< const v
77
- cursorSet (JField c i ) v = foldJson (const d ) (const d ) (const d ) (const d ) (const d ) g where
77
+ cursorSet (JField i c ) v = foldJson (const d ) (const d ) (const d ) (const d ) (const d ) g where
78
78
d = fromObject <<< M. singleton i <$> cursorSet c v (inferEmpty c )
79
79
g m = fromObject <<< flip (M.insert i ) m <$> (cursorSet c v $ fromMaybe (inferEmpty c) (M.lookup i m))
80
- cursorSet (JIndex c i ) v = foldJson (const d ) (const d ) (const d ) (const d ) g (const d ) where
80
+ cursorSet (JIndex i c ) v = foldJson (const d ) (const d ) (const d ) (const d ) g (const d ) where
81
81
d = fromArray <<< flip (A.updateAt i ) (const jsonNull <$> A.range 0 i ) <$> cursorSet c v (inferEmpty c )
82
82
g a = (cursorSet c v $ fromMaybe (inferEmpty c) (a A.!! i)) >>= setArr a i
83
83
@@ -95,10 +95,10 @@ module Data.Argonaut.JCursor
95
95
(\s -> [Tuple JCursorTop $ primStr s ])
96
96
(\a -> let zipped = A.zipWith Tuple (A.range 0 (A.length a - 1)) a
97
97
98
- f (Tuple i j ) = (\t -> Tuple (JIndex (fst t) i ) (snd t )) <$> toPrims j
98
+ f (Tuple i j ) = (\t -> Tuple (JIndex i (fst t)) (snd t )) <$> toPrims j
99
99
100
100
in zipped >>= f)
101
- (\o -> let f (Tuple i j) = (\t -> Tuple (JField (fst t) i ) (snd t )) <$> toPrims j
101
+ (\o -> let f (Tuple i j) = (\t -> Tuple (JField i (fst t)) (snd t )) <$> toPrims j
102
102
in M. toList o >>= f)
103
103
104
104
fromPrims :: [Tuple JCursor JsonPrim ] -> Maybe Json
@@ -108,16 +108,16 @@ module Data.Argonaut.JCursor
108
108
109
109
instance showJCursor :: Show JCursor where
110
110
show JCursorTop = " "
111
- show (JField c i ) = " ." ++ i ++ show c
112
- show (JIndex c i ) = " [" ++ show i ++ " ]" ++ show c
111
+ show (JField i c ) = " ." ++ i ++ show c
112
+ show (JIndex i c ) = " [" ++ show i ++ " ]" ++ show c
113
113
114
114
instance showJsonPrim :: Show JsonPrim where
115
115
show p = runJsonPrim p show show show show
116
116
117
117
instance eqJCursor :: Eq JCursor where
118
118
(==) JCursorTop JCursorTop = true
119
- (==) (JField c1 i1 ) (JField c2 i2 ) = i1 == i2 && c1 == c2
120
- (==) (JIndex c1 i1 ) (JIndex c2 i2 ) = i1 == i2 && c1 == c2
119
+ (==) (JField i1 c1 ) (JField i2 c2 ) = i1 == i2 && c1 == c2
120
+ (==) (JIndex i1 c1 ) (JIndex i2 c2 ) = i1 == i2 && c1 == c2
121
121
(==) _ _ = false
122
122
123
123
(/=) a b = not (a == b )
@@ -128,18 +128,18 @@ module Data.Argonaut.JCursor
128
128
compare _ JCursorTop = GT
129
129
compare (JField _ _ ) (JIndex _ _ ) = LT
130
130
compare (JIndex _ _ ) (JField _ _ ) = GT
131
- compare (JField c1 i1 ) (JField c2 i2 ) = case compare i1 i2 of
131
+ compare (JField i1 c1 ) (JField i2 c2 ) = case compare i1 i2 of
132
132
EQ -> compare c1 c2
133
133
x -> x
134
- compare (JIndex c1 i1 ) (JIndex c2 i2 ) = case compare i1 i2 of
134
+ compare (JIndex i1 c1 ) (JIndex i2 c2 ) = case compare i1 i2 of
135
135
EQ -> compare c1 c2
136
136
x -> x
137
137
138
138
instance semigroupJCursor :: Semigroup JCursor where
139
139
(<>) a JCursorTop = a
140
140
(<>) JCursorTop b = b
141
- (<>) (JField a i ) b = JField (a <> b ) i
142
- (<>) (JIndex a i ) b = JIndex (a <> b ) i
141
+ (<>) (JField i a ) b = JField i (a <> b )
142
+ (<>) (JIndex i a ) b = JIndex i (a <> b )
143
143
144
144
instance monoidJCursor :: Monoid JCursor where
145
145
mempty = JCursorTop
0 commit comments