diff --git a/advanced/part6/src/Author.elm b/advanced/part6/src/Author.elm index ad3b83b..e7de3c5 100644 --- a/advanced/part6/src/Author.elm +++ b/advanced/part6/src/Author.elm @@ -206,17 +206,14 @@ toggleFollowButton txt extraClasses msgWhenClicked uname = decoder : Maybe Cred -> Decoder Author decoder maybeCred = - {- 👉 TODO: Use this `Profile` and `Username` to decode an `Author`! - - 💡 HINT: `decoderHelp` will help here, but slightly altering its type may make things easier... - -} - Decode.succeed "..." + Decode.succeed Tuple.pair |> custom Profile.decoder |> required "username" Username.decoder + |> Decode.andThen (decodeFromPair maybeCred) -decoderHelp : Maybe Cred -> Profile -> Username -> Decoder Author -decoderHelp maybeCred prof uname = +decodeFromPair : Maybe Cred -> ( Profile, Username ) -> Decoder Author +decodeFromPair maybeCred ( prof, uname ) = case maybeCred of Nothing -> -- If you're logged out, you can't be following anyone! diff --git a/advanced/part6/src/Timestamp.elm b/advanced/part6/src/Timestamp.elm index aa2eb7c..fde03e0 100644 --- a/advanced/part6/src/Timestamp.elm +++ b/advanced/part6/src/Timestamp.elm @@ -24,17 +24,18 @@ view timeZone timestamp = -} iso8601Decoder : Decoder Time.Posix iso8601Decoder = - {- 👉 TODO: Use the following function to decode this Time.Posix value: + Decode.string + |> Decode.andThen fromString - Iso8601.toTime : String -> Result (List DeadEnd) Time.Posix +fromString : String -> Decoder Time.Posix +fromString str = + case Iso8601.toTime str of + Ok successValue -> + succeed successValue - - ❕ NOTE: You can disregard the (List DeadEnd) here. No need to use it to complete this exercise! - - 💡 HINT: Decode.andThen will be useful here. - -} - "..." + Err _ -> + fail ("Invalid date: " ++ str) diff --git a/advanced/part7/src/Author.elm b/advanced/part7/src/Author.elm index e7de3c5..ad3b83b 100644 --- a/advanced/part7/src/Author.elm +++ b/advanced/part7/src/Author.elm @@ -206,14 +206,17 @@ toggleFollowButton txt extraClasses msgWhenClicked uname = decoder : Maybe Cred -> Decoder Author decoder maybeCred = - Decode.succeed Tuple.pair + {- 👉 TODO: Use this `Profile` and `Username` to decode an `Author`! + + 💡 HINT: `decoderHelp` will help here, but slightly altering its type may make things easier... + -} + Decode.succeed "..." |> custom Profile.decoder |> required "username" Username.decoder - |> Decode.andThen (decodeFromPair maybeCred) -decodeFromPair : Maybe Cred -> ( Profile, Username ) -> Decoder Author -decodeFromPair maybeCred ( prof, uname ) = +decoderHelp : Maybe Cred -> Profile -> Username -> Decoder Author +decoderHelp maybeCred prof uname = case maybeCred of Nothing -> -- If you're logged out, you can't be following anyone! diff --git a/advanced/part7/src/Timestamp.elm b/advanced/part7/src/Timestamp.elm index fde03e0..aa2eb7c 100644 --- a/advanced/part7/src/Timestamp.elm +++ b/advanced/part7/src/Timestamp.elm @@ -24,18 +24,17 @@ view timeZone timestamp = -} iso8601Decoder : Decoder Time.Posix iso8601Decoder = - Decode.string - |> Decode.andThen fromString + {- 👉 TODO: Use the following function to decode this Time.Posix value: -fromString : String -> Decoder Time.Posix -fromString str = - case Iso8601.toTime str of - Ok successValue -> - succeed successValue + Iso8601.toTime : String -> Result (List DeadEnd) Time.Posix - Err _ -> - fail ("Invalid date: " ++ str) + + ❕ NOTE: You can disregard the (List DeadEnd) here. No need to use it to complete this exercise! + + 💡 HINT: Decode.andThen will be useful here. + -} + "..."