Skip to content

Commit 901a792

Browse files
committed
Expose emptyArray and emptyObject
1 parent 986e0e0 commit 901a792

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Switch from `Chunks` to `SmallArray` in the `Object` and `Array` data
66
constructors. This makes the library simpler to use but it a breaking
77
change.
8+
* Expose `emptyArray` and `emptyObject`.
89
* Add `object(9|10|11|12)` as convenience helpers for construction.
910

1011
## 0.1.2.0 -- 2020-11-18

src/Json.hs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ module Json
2121
, encode
2222
-- * Infix Synonyms
2323
, pattern (:->)
24+
-- * Constants
25+
, emptyArray
26+
, emptyObject
2427
-- * Construction
2528
, object1
2629
, object2
@@ -121,13 +124,15 @@ data Member = Member
121124
, value :: !Value
122125
} deriving stock (Eq,Show)
123126

124-
emptyArrayValue :: Value
125-
{-# noinline emptyArrayValue #-}
126-
emptyArrayValue = Array mempty
127+
-- | An array with no elements (i.e. @[]@)
128+
emptyArray :: Value
129+
{-# noinline emptyArray #-}
130+
emptyArray = Array mempty
127131

128-
emptyObjectValue :: Value
129-
{-# noinline emptyObjectValue #-}
130-
emptyObjectValue = Object mempty
132+
-- | An object with no members (i.e. @{}@)
133+
emptyObject :: Value
134+
{-# noinline emptyObject #-}
135+
emptyObject = Object mempty
131136

132137
isSpace :: Word8 -> Prelude.Bool
133138
{-# inline isSpace #-}
@@ -225,7 +230,7 @@ objectTrailedByBrace :: Parser SyntaxException s Value
225230
objectTrailedByBrace = do
226231
P.skipWhile isSpace
227232
Latin.any IncompleteObject >>= \case
228-
'}' -> pure emptyObjectValue
233+
'}' -> pure emptyObject
229234
'"' -> do
230235
start <- Unsafe.cursor
231236
!theKey <- string id start
@@ -273,7 +278,7 @@ arrayTrailedByBracket :: Parser SyntaxException s Value
273278
arrayTrailedByBracket = do
274279
P.skipWhile isSpace
275280
Latin.any IncompleteArray >>= \case
276-
']' -> pure emptyArrayValue
281+
']' -> pure emptyArray
277282
c -> do
278283
!b0 <- P.effect B.new
279284
val <- parser c

0 commit comments

Comments
 (0)