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 "http://elm-in-action.com/photos/list.json" 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://elm-in-action.com/photos/list.json"
        |> 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 http://elm-in-action.com/{filename}.jpeg and the Photo URI template is http://elm-in-action.com/large/{filename}.jpeg.