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 2954fd9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lambda-buffers-codegen/src/LambdaBuffers/Codegen/LamVal/Json.hs
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,11 @@ 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
]
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 2954fd9

Please sign in to comment.