@@ -129,13 +129,6 @@ defElmImports =
129 , "import Http"
129 , "import Http"
130 , "import String"
130 , "import String"
131 , "import Url.Builder"
131 , "import Url.Builder"
133− , "maybeBoolToIntStr : Maybe Bool -> String"
134− , "maybeBoolToIntStr mx ="
136− , " Nothing -> \"\""
137− , " Just True -> \"1\""
138− , " Just False -> \"0\""
@@ -396,7 +389,7 @@ mkLetParams opts request =
396 argType = qarg ^. F.queryArgName . F.argType
389 argType = qarg ^. F.queryArgName . F.argType
397 wrapped = isElmMaybeType argType
390 wrapped = isElmMaybeType argType
398 toStringSrc =
391 toStringSrc =
399− toString opts argType
392+ toString opts (maybeOf argType)
401 "[" <+> (if wrapped then elmName else "Just" <+> elmName) <> line <>
394 "[" <+> (if wrapped then elmName else "Just" <+> elmName) <> line <>
402 (indent 4 ("|> Maybe.map" <+> composeRight [toStringSrc, "Url.Builder.string" <+> dquotes name]))
395 (indent 4 ("|> Maybe.map" <+> composeRight [toStringSrc, "Url.Builder.string" <+> dquotes name]))
@@ -416,18 +409,18 @@ mkLetParams opts request =
416 F.List ->
409 F.List ->
418 argType = qarg ^. F.queryArgName . F.argType
411 argType = qarg ^. F.queryArgName . F.argType
419− convertedVal =
412+ toStringSrc =
420− if isElmListOfMaybeBoolType argType then
413+ toString opts (listOf (maybeOf argType))
421− parens ("maybeBoolToIntStr" <+> "val")
425 elmName <$>
415 elmName <$>
426 indent 4 ("|> List.map"
416 indent 4 ("|> List.map"
427− <+> parens (backslash <> "val ->" <+> "Just"
417+ <+> composeRight
428− <+> parens ("Url.Builder.string"
419+ , "Url.Builder.string" <+> dquotes (name <> "[]")
429− <+> dquotes (name <> "[]")
420+ , "Just"
430− <+> convertedVal)))
421+ ]
432 elmName = elmQueryArg qarg
425 elmName = elmQueryArg qarg
433 name = qarg ^. F.queryArgName . F.argName . to (stext . F.unPathSegment)
426 name = qarg ^. F.queryArgName . F.argName . to (stext . F.unPathSegment)
@@ -463,9 +456,9 @@ mkRequest opts request =
463 headerArgName = elmHeaderArg header
456 headerArgName = elmHeaderArg header
464 argType = header ^. F.headerArg . F.argType
457 argType = header ^. F.headerArg . F.argType
465 wrapped = isElmMaybeType argType
458 wrapped = isElmMaybeType argType
466− toStringSrc = toString opts argType
459+ toStringSrc = toString opts (maybeOf argType)
468− "Maybe.map" <+> parens (("Http.header" <+> composeLeft [dquotes headerName, toStringSrc]))
461+ "Maybe.map" <+> composeLeft ["Http.header" <+> dquotes headerName, toStringSrc]
470 (if wrapped then headerArgName else parens ("Just" <+> headerArgName))
463 (if wrapped then headerArgName else parens ("Just" <+> headerArgName))
@@ -557,7 +550,7 @@ mkUrl opts segments =
557 F.Cap arg ->
550 F.Cap arg ->
559 toStringSrc =
552 toStringSrc =
560− toString opts (arg ^. F.argType)
553+ toString opts (maybeOf (arg ^. F.argType))
562 pipeRight [elmCaptureArg s, toStringSrc]
555 pipeRight [elmCaptureArg s, toStringSrc]
@@ -628,13 +621,23 @@ defaultElmToString :: EType -> Text
628defaultElmToString argType =
621defaultElmToString argType =
629 case argType of
622 case argType of
630 ETyCon (ETCon "Bool") -> "(\\value -> if value then \"1\" else \"0\")"
623 ETyCon (ETCon "Bool") -> "(\\value -> if value then \"1\" else \"0\")"
631− ETyCon (ETCon "Posix") -> "Time.posixToMillis >> String.fromInt)"
624+ ETyCon (ETCon "Float") -> "String.fromFloat"
625+ ETyCon (ETCon "Char") -> "String.fromChar"
632− ETyApp (ETyCon (ETCon "Maybe")) v -> defaultElmToString v
626+ ETyApp (ETyCon (ETCon "Maybe")) v -> "(Maybe.map " <> defaultElmToString v <> " >> Maybe.withDefault \"\")"
633 _ -> "String.fromInt"
627 _ -> "String.fromInt"
630+maybeOf :: EType -> EType
631+maybeOf (ETyApp (ETyCon (ETCon "Maybe")) v) = v
634+listOf :: EType -> EType
635+listOf (ETyApp (ETyCon (ETCon "List")) v) = v
635toString :: ElmOptions -> EType -> Doc
638toString :: ElmOptions -> EType -> Doc
636toString opts argType =
639toString opts argType =
637− if isElmStringType opts argType || isElmMaybeStringType opts argType then
640+ if isElmStringType opts argType then
640 stext $ elmToString opts argType
643 stext $ elmToString opts argType