Skip to content

Commit f301243

Browse files
Add module documentation for 'Data.MonoidMap.JSON'.
1 parent 36793c8 commit f301243

File tree

1 file changed

+47
-1
lines changed
  • components/monoidmap-aeson/Data/MonoidMap

1 file changed

+47
-1
lines changed

components/monoidmap-aeson/Data/MonoidMap/JSON.hs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,53 @@
44
-- Copyright: © 2022–2025 Jonathan Knowles
55
-- License: Apache-2.0
66
--
7-
module Data.MonoidMap.JSON where
7+
-- This module provides instances of 'ToJSON' and 'FromJSON' for 'MonoidMap'.
8+
--
9+
-- These instances provide objects of type 'MonoidMap' __@k@__ __@v@__ with a
10+
-- JSON encoding identical to that of 'Map' __@k@__ __@v@__, serialised as
11+
-- either JSON /objects/ or /arrays/ depending on the key type __@k@__.
12+
--
13+
-- = Examples
14+
--
15+
-- === Encoding as JSON objects
16+
--
17+
-- @
18+
-- >>> 'encode' '$' 'fromList' [("abc", 'Sum' 1), ("def", 'Sum' 2)]
19+
-- "{\\"abc\\":1,\\"def\\":2}"
20+
-- @
21+
--
22+
-- === Encoding as JSON arrays
23+
--
24+
-- @
25+
-- >>> 'encode' '$' 'fromList' [((1,2), 'Sum' 3), ((2,3), 'Sum' 5)]
26+
-- "[[[1,2],3],[[2,3],5]]"
27+
-- @
28+
--
29+
-- = Laws
30+
--
31+
-- == Decoding from JSON
32+
--
33+
-- The 'FromJSON' instance satisfies the following law:
34+
--
35+
-- @
36+
-- 'parseJSON' '==' 'fmap' ('fmap' 'MonoidMap'.'fromMap') 'parseJSON'
37+
-- @
38+
--
39+
-- Mappings from keys to values that decode to 'mempty' are __not__ included in
40+
-- decoded 'MonoidMap' objects.
41+
--
42+
-- == Encoding to JSON
43+
--
44+
-- The 'ToJSON' instance satisfies the following laws:
45+
--
46+
-- @
47+
-- 'toEncoding' '==' 'toEncoding' '.' 'MonoidMap'.'toMap'
48+
-- 'toJSON' '==' 'toJSON' '.' 'MonoidMap'.'toMap'
49+
-- @
50+
--
51+
module Data.MonoidMap.JSON
52+
()
53+
where
854

955
import Prelude
1056

0 commit comments

Comments
 (0)