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
#1
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
http://package.elm-lang.org/packages/elm-lang/http/1.0.0/Http

It is easy to get sidetracked to
http://package.elm-lang.org/packages/evancz/elm-http/3.0.1/Http
by
http://package.elm-lang.org/packages/evancz/elm-http/latest/Http


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

{-
initialCmd : Cmd Msg
initialCmd =
    let
        decoder = list photoDecoder
        request = Http.get "http://elm-in-action.com/photos/list.json" decoder
        -- Http.get : String -> Decoder a -> Request a
    in
        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.