Skip to content

Commit 6402a87

Browse files
committed
add documentation to EncodeRepRowList
1 parent ad1ec83 commit 6402a87

File tree

1 file changed

+14
-1
lines changed
  • src/Data/Argonaut/Encode/Generic

1 file changed

+14
-1
lines changed

src/Data/Argonaut/Encode/Generic/Rep.purs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,24 @@ instance encodeRepFieldsProduct :: (EncodeRepFields a, EncodeRepFields b) => Enc
6969
FO.union (encodeRepFields a) (encodeRepFields b)
7070

7171

72+
-- | a `EncodeRepRowList` represents a relation between a `RowList` and a record you
73+
-- | can serialize into a Json `Object`
74+
-- |
75+
-- | this one is strictly internal to help out `encodeRepRecordArgument` handling records
76+
-- |
77+
-- | a `RowList` on the type level is very similar to a *cons-list* on the value level
78+
-- | so the two instances handle all possible `RowList`s
79+
-- |
80+
-- | the idea is use the `Cons` cases to to compose functions that adds the field
81+
-- | and values from the given record into a Json-`Object`
82+
-- | the field in question is indicated by the head of the `RowList`
83+
-- |
84+
-- | the `Nil` case just returns `identity` to bootstrap the composition-chain
7285
class EncodeRepRowList (rl :: RowList) (row :: #Type) | rl -> row where
7386
encodeRepRowList :: forall g . g rl -> Record row -> (FO.Object Json -> FO.Object Json)
7487

7588
instance encodeRepRowListNil :: EncodeRepRowList Nil row where
76-
encodeRepRowList _ _ = \obj -> obj
89+
encodeRepRowList _ _ = identity
7790

7891
instance encodeRepRowListCons :: (EncodeJson ty, IsSymbol name, EncodeRepRowList tail row, Row.Cons name ty ignore row) => EncodeRepRowList (Cons name ty tail) row where
7992
encodeRepRowList _ rec = \obj -> FO.insert (reflectSymbol namep) (encodeJson value) (cont obj)

0 commit comments

Comments
 (0)