@@ -177,8 +177,10 @@ toMaybe tipe =
177 Opt.Var (Var.inCore ["Maybe"] tag)
177 Opt.Var (Var.inCore ["Maybe"] tag)
179 to "oneOf" <==
179 to "oneOf" <==
180− [ to "null" <== [ maybe "Nothing" ]
181+ [ to "null" <== [ maybe "Nothing" ]
181− , to "map" <== [ maybe "Just", decode tipe ]
182+ , to "map" <== [ maybe "Just", decode tipe ]
@@ -199,16 +201,13 @@ toTuple types =
199toRecord :: [(String, T.Canonical)] -> Opt.Expr
201toRecord :: [(String, T.Canonical)] -> Opt.Expr
200toRecord fields =
202toRecord fields =
202− keys =
204+ toFieldExpr (key, _) =
206 (key, Opt.Var (Var.local key))
205 (key, Opt.Var (Var.local key))
208− rootExpr =
207+ finalDecoder =
209− to "succeed" <== [ Opt.Function keys (Opt.Record (map toField keys)) ]
208+ to "succeed" <== [ Opt.Record (map toFieldExpr fields) ]
211− andMap root (key, tipe) =
210+ andThen (key, tipe) decoder =
212− to "andMap" <== [ root, key =: decode tipe ]
211+ to "andThen" <== [ key =: decode tipe, Opt.Function [key] decoder ]
214− List.foldl' andMap rootExpr fields
213+ List.foldr andThen finalDecoder fields