Skip to content

Commit

Permalink
Fix dict
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSStewart committed May 8, 2024
1 parent d3610a0 commit 2fd0e1e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Internal/Builtin/MiniBillCodec.elm
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ codeGen =
, CodeGenerator.string (val "string")
, CodeGenerator.list (fn1 "list")
, CodeGenerator.maybe (fn1 "nullable")
, CodeGenerator.dict (\key value -> CG.apply [ val "dict", key, value ])
, CodeGenerator.dict
(\key value ->
CG.apply
[ val "map"
, CG.fqVal [ "Dict" ] "fromList"
, CG.fqVal [ "Dict" ] "toList"
, CG.apply [ val "list", CG.apply [ val "tuple", key, value ] ]
]
)
, CodeGenerator.unit (val "unit")
, CodeGenerator.tuple (\arg1 arg2 -> CG.apply [ val "tuple", arg1, arg2 ])
, CodeGenerator.triple (\arg1 arg2 arg3 -> CG.apply [ val "tuple", arg1, arg2, arg3 ])
Expand Down
7 changes: 6 additions & 1 deletion tests/MiniBillCodecCodeGenTest.elm
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ type alias MyType =
codec : Codec MyType
codec =
Codec.object MyType |> Codec.field "fieldA" .fieldA (Codec.dict Codec.int Codec.string) |> Codec.buildObject
Codec.object MyType
|> Codec.field
"fieldA"
.fieldA
(Codec.map Dict.fromList Dict.toList (Codec.list (Codec.tuple Codec.int Codec.string)))
|> Codec.buildObject
"""
, codeGenTest "nested record codec"
[ elmCodec ]
Expand Down

0 comments on commit 2fd0e1e

Please sign in to comment.