Solution for advanced/part7

This commit is contained in:
Richard Feldman
2018-08-14 03:46:22 -04:00
parent f744cad4f9
commit 3ec84cb051
2 changed files with 13 additions and 15 deletions

View File

@@ -206,17 +206,14 @@ toggleFollowButton txt extraClasses msgWhenClicked uname =
decoder : Maybe Cred -> Decoder Author decoder : Maybe Cred -> Decoder Author
decoder maybeCred = decoder maybeCred =
{- 👉 TODO: Use this `Profile` and `Username` to decode an `Author`! Decode.succeed Tuple.pair
💡 HINT: `decoderHelp` will help here, but slightly altering its type may make things easier...
-}
Decode.succeed "..."
|> custom Profile.decoder |> custom Profile.decoder
|> required "username" Username.decoder |> required "username" Username.decoder
|> Decode.andThen (decoderHelp maybeCred)
decoderHelp : Maybe Cred -> Profile -> Username -> Decoder Author decoderHelp : Maybe Cred -> ( Profile, Username ) -> Decoder Author
decoderHelp maybeCred prof uname = decoderHelp maybeCred ( prof, uname ) =
case maybeCred of case maybeCred of
Nothing -> Nothing ->
-- If you're logged out, you can't be following anyone! -- If you're logged out, you can't be following anyone!

View File

@@ -24,17 +24,18 @@ view timeZone timestamp =
-} -}
iso8601Decoder : Decoder Time.Posix iso8601Decoder : Decoder Time.Posix
iso8601Decoder = iso8601Decoder =
{- 👉 TODO: Use the following function to decode this Time.Posix value: Decode.string
|> Decode.andThen decoderHelp
Iso8601.toTime : String -> Result (List DeadEnd) Time.Posix decoderHelp : String -> Decoder Time.Posix
decoderHelp str =
case Iso8601.toTime str of
Ok time ->
Decode.succeed time
Err _ ->
NOTE: You can disregard the (List DeadEnd) here. No need to use it to complete this exercise! Decode.fail ("Invalid ISO-8601 timestamp: " ++ str)
💡 HINT: Decode.andThen will be useful here.
-}
"..."