@@ -177,8 +177,10 @@ toMaybe tipe =
177177 Opt.Var (Var.inCore ["Maybe"] tag)
178178 in
179179 to "oneOf" <==
180− [ to "null" <== [ maybe "Nothing" ]
181− , to "map" <== [ maybe "Just", decode tipe ]
180+ [ Opt.ExplicitList
181+ [ to "null" <== [ maybe "Nothing" ]
182+ , to "map" <== [ maybe "Just", decode tipe ]
183+ ]
182184 ]
183185
184186
@@ -199,16 +201,13 @@ toTuple types =
199201toRecord :: [(String, T.Canonical)] -> Opt.Expr
200202toRecord fields =
201203 let
202− keys =
203− map fst fields
204−
205− toField key =
204+ toFieldExpr (key, _) =
206205 (key, Opt.Var (Var.local key))
207206
208− rootExpr =
209− to "succeed" <== [ Opt.Function keys (Opt.Record (map toField keys)) ]
207+ finalDecoder =
208+ to "succeed" <== [ Opt.Record (map toFieldExpr fields) ]
210209
211− andMap root (key, tipe) =
212− to "andMap" <== [ root, key =: decode tipe ]
210+ andThen (key, tipe) decoder =
211+ to "andThen" <== [ key =: decode tipe, Opt.Function [key] decoder ]
213212 in
214− List.foldl' andMap rootExpr fields
213+ List.foldr andThen finalDecoder fields