Skip to content

Commit

Permalink
Allow empty records for JSON generation
Browse files Browse the repository at this point in the history
  • Loading branch information
jared committed Apr 9, 2024
1 parent 887c17a commit 0dcef38
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions lambda-buffers-codegen/src/LambdaBuffers/Codegen/LamVal/Json.hs
Original file line number Diff line number Diff line change
Expand Up @@ -264,15 +264,10 @@ fromJsonProduct ty qprod@(qtyN, prodTy) =
toJsonRecord :: QRecord -> ValueE
toJsonRecord (qtyN, recTy) =
LamE
( \recVal ->
case OMap.assocs recTy of
[] -> ErrorE "Got an empty Record type to print in `toJsonRecord`"
_ ->
jsonObjRef
@ ListE
[ TupleE (fieldNameVal fieldName) (toJsonRef fieldTy @ FieldE (qtyN, fieldName) recVal)
| (fieldName, fieldTy) <- sortOn fst $ OMap.assocs recTy
]
( \recVal -> jsonObjRef @ ListE
[ TupleE (fieldNameVal fieldName) (toJsonRef fieldTy @ FieldE (qtyN, fieldName) recVal)
| (fieldName, fieldTy) <- sortOn fst $ OMap.assocs recTy
]
)

{- | `fromJsonRecord ty qrec` makes a `LamVal` function for decoding record type values from their JSON representation `fromJson :: Json -> Parser <ty>`.
Expand Down

0 comments on commit 0dcef38

Please sign in to comment.