Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 3f71847

Browse files
garybcryogenian
authored andcommitted
Make EJson Show-able (#14)
* Make `EJson` `Show`-able * Make `Cursor` `Show`-able
1 parent 5934762 commit 3f71847

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

src/Data/Json/Extended/Cursor.purs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import Data.Array as A
66
import Data.Bifunctor (lmap)
77
import Data.Eq (class Eq1)
88
import Data.Functor.Mu (Mu)
9-
import Data.Json.Extended (EJson, renderEJson)
9+
import Data.Json.Extended (EJson)
1010
import Data.Json.Extended as EJ
1111
import Data.Maybe (Maybe(..), maybe)
1212
import Data.Ord (class Ord1)
13+
import Data.TacitString (TacitString)
1314
import Data.Tuple (Tuple(..), lookup)
1415

1516
import Matryoshka (Algebra, cata, project, embed)
@@ -47,14 +48,18 @@ derive instance ordCursor ∷ Ord a ⇒ Ord (CursorF a)
4748

4849
instance eq1CursorFEq1 CursorF where
4950
eq1 = eq
51+
5052
instance ord1CursorFOrd1 CursorF where
5153
compare1 = compare
5254

55+
instance showCursorFShow (CursorF TacitString) where
56+
show = case _ of
57+
All"All"
58+
AtKey k a → "(AtKey " <> show k <> " " <> show a <> ")"
59+
AtIndex i a → "(AtIndex " <> show i <> " " <> show a <> ")"
60+
5361
renderEJsonCursor Cursor String
54-
renderEJsonCursor = cata case _ of
55-
All"All"
56-
AtKey ejson a → "(AtKey " <> renderEJson ejson <> " " <> a <> ")"
57-
AtIndex i a → "(AtIndex " <> show i <> " " <> a <> ")"
62+
renderEJsonCursor = show
5863

5964
-- | Peels off one layer of a cursor, if possible. The resulting tuple contains
6065
-- | the current step (made relative), and the remainder of the cursor.

src/Data/Json/Extended/Signature/Core.purs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Data.List as L
1616
import Data.Monoid (mempty)
1717
import Data.Ord (class Ord1)
1818
import Data.Tuple (Tuple(..))
19+
import Data.TacitString (TacitString)
1920

2021
-- | The signature endofunctor for the EJson theory.
2122
data EJsonF a
@@ -78,8 +79,6 @@ instance traversableEJsonF ∷ T.Traversable EJsonF where
7879
ObjectId oid → pure $ ObjectId oid
7980
sequence = T.sequenceDefault
8081

81-
82-
8382
instance eq1EJsonFEq1 EJsonF where
8483
eq1 Null Null = true
8584
eq1 (Boolean b1) (Boolean b2) = b1 == b2
@@ -131,6 +130,21 @@ derive instance ordEJsonF ∷ Ord a ⇒ Ord (EJsonF a)
131130
instance ord1EJsonFOrd1 EJsonF where
132131
compare1 = compare
133132

133+
instance showEJsonFShow (EJsonF TacitString) where
134+
show = case _ of
135+
Null"Null"
136+
String s → "(String " <> show s <> ")"
137+
Boolean b → "(Boolean " <> show b <> ")"
138+
Integer i → "(Integer " <> show i <> ")"
139+
Decimal n → "(Decimal " <> show n <> ")"
140+
Timestamp r → "(Timestamp " <> show r <> ")"
141+
Date d → "(Date " <> show d <> ")"
142+
Time t → "(Time " <> show t <> ")"
143+
Interval i → "(Interval " <> show i <> ")"
144+
ObjectId i → "(ObjectId " <> show i <> ")"
145+
Array xs → "(Array " <> show xs <> ")"
146+
Map kvs → "(Map " <> show kvs <> ")"
147+
134148
getType a. EJsonF a JT.EJsonType
135149
getType = case _ of
136150
NullJT.Null

0 commit comments

Comments
 (0)