@@ -129,13 +129,6 @@ defElmImports =
129129 , "import Http"
130130 , "import String"
131131 , "import Url.Builder"
132− , ""
133− , "maybeBoolToIntStr : Maybe Bool -> String"
134− , "maybeBoolToIntStr mx ="
135− , " case mx of"
136− , " Nothing -> \"\""
137− , " Just True -> \"1\""
138− , " Just False -> \"0\""
139132 ]
140133
141134{-|
@@ -396,7 +389,7 @@ mkLetParams opts request =
396389 argType = qarg ^. F.queryArgName . F.argType
397390 wrapped = isElmMaybeType argType
398391 toStringSrc =
399− toString opts argType
392+ toString opts (maybeOf argType)
400393 in
401394 "[" <+> (if wrapped then elmName else "Just" <+> elmName) <> line <>
402395 (indent 4 ("|> Maybe.map" <+> composeRight [toStringSrc, "Url.Builder.string" <+> dquotes name]))
@@ -416,18 +409,18 @@ mkLetParams opts request =
416409 F.List ->
417410 let
418411 argType = qarg ^. F.queryArgName . F.argType
419− convertedVal =
420− if isElmListOfMaybeBoolType argType then
421− parens ("maybeBoolToIntStr" <+> "val")
422− else
423− "val"
412+ toStringSrc =
413+ toString opts (listOf (maybeOf argType))
424414 in
425415 elmName <$>
426416 indent 4 ("|> List.map"
427− <+> parens (backslash <> "val ->" <+> "Just"
428− <+> parens ("Url.Builder.string"
429− <+> dquotes (name <> "[]")
430− <+> convertedVal)))
417+ <+> composeRight
418+ [ toStringSrc
419+ , "Url.Builder.string" <+> dquotes (name <> "[]")
420+ , "Just"
421+ ]
422+ )
423+
431424 where
432425 elmName = elmQueryArg qarg
433426 name = qarg ^. F.queryArgName . F.argName . to (stext . F.unPathSegment)
@@ -463,9 +456,9 @@ mkRequest opts request =
463456 headerArgName = elmHeaderArg header
464457 argType = header ^. F.headerArg . F.argType
465458 wrapped = isElmMaybeType argType
466− toStringSrc = toString opts argType
459+ toStringSrc = toString opts (maybeOf argType)
467460 in
468− "Maybe.map" <+> parens (("Http.header" <+> composeLeft [dquotes headerName, toStringSrc]))
461+ "Maybe.map" <+> composeLeft ["Http.header" <+> dquotes headerName, toStringSrc]
469462 <+>
470463 (if wrapped then headerArgName else parens ("Just" <+> headerArgName))
471464
@@ -557,7 +550,7 @@ mkUrl opts segments =
557550 F.Cap arg ->
558551 let
559552 toStringSrc =
560− toString opts (arg ^. F.argType)
553+ toString opts (maybeOf (arg ^. F.argType))
561554 in
562555 pipeRight [elmCaptureArg s, toStringSrc]
563556
@@ -628,13 +621,23 @@ defaultElmToString :: EType -> Text
628621defaultElmToString argType =
629622 case argType of
630623 ETyCon (ETCon "Bool") -> "(\\value -> if value then \"1\" else \"0\")"
631− ETyCon (ETCon "Posix") -> "Time.posixToMillis >> String.fromInt)"
632− ETyApp (ETyCon (ETCon "Maybe")) v -> defaultElmToString v
624+ ETyCon (ETCon "Float") -> "String.fromFloat"
625+ ETyCon (ETCon "Char") -> "String.fromChar"
626+ ETyApp (ETyCon (ETCon "Maybe")) v -> "(Maybe.map " <> defaultElmToString v <> " >> Maybe.withDefault \"\")"
633627 _ -> "String.fromInt"
634628
629+
630+maybeOf :: EType -> EType
631+maybeOf (ETyApp (ETyCon (ETCon "Maybe")) v) = v
632+maybeOf v = v
633+
634+listOf :: EType -> EType
635+listOf (ETyApp (ETyCon (ETCon "List")) v) = v
636+listOf v = v
637+
635638toString :: ElmOptions -> EType -> Doc
636639toString opts argType =
637− if isElmStringType opts argType || isElmMaybeStringType opts argType then
640+ if isElmStringType opts argType then
638641 mempty
639642 else
640643 stext $ elmToString opts argType