The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

tempusfugit (144) [Avatar] Offline
For the time being "part 2" remains a work in progress.

Page 113(117):
4.3.3 Decoding JSON HTTP Responses >> Http.get

A Warning to readers:

When looking at the official documentation make sure you are looking at

It is easy to get sidetracked to

Yes, the the pipeline style of initialCmd is concise but is also wonderfully opaque from a learning perspective.

initialCmd : Cmd Msg
initialCmd =
        decoder = list photoDecoder
        request = Http.get "" decoder
        -- Http.get : String -> Decoder a -> Request a
        Http.send LoadPhotos request

        -- Http.send : (Result Error a -> msg) -> Request a -> Cmd msg

        -- i.e. LoadPhotos is a data constructor which creates a Msg type instance
        -- from a (Result Http.Error (List Photo)) type instance.
        -- So LoadPhotos satisfies (Result Error a -> msg) 
        -- when a = (List Photo), msg = Msg

or more concisely:

initialCmd : Cmd Msg
initialCmd =
    list photoDecoder
        |> Http.get ""
        |> Http.send LoadPhotos

At this point it occurs to me that given its relationship to the Photo type the function name viewThumbnail is more than a little misleading - it should be renamed to something like viewPhoto - or alternately rename the Photo type to Thumbnail if the Thumbnail URI template is{filename}.jpeg and the Photo URI template is{filename}.jpeg.