This is what I landed on for the Json decoding:

decodeProjects : Json.Value -> List Project
decodeProjects jsonResponse =
  case decodeValue (list decodeProject) jsonResponse of
    Ok val -> val
    Err msg -> Debug.crash msg


-- taken from http:
//package.elm-lang.org/packages/circuithub/elm-json-extra/2.2.1/Json-Decode-Extra
(|:) : Decoder (a -> b) -> Decoder a -> Decoder b
(|:) f aDecoder =
  f `andThen` (\f' -> f' `map` aDecoder)


decodeProject : Decoder Project
decodeProject =
  succeed Project
    |: ( "projectName" := string )
    |: ( "repoUrl" := string )
    |: ( "description" := string )
    -- etc.


I couldn't figure out any other way to map out the project than with using 
the |: operator from the library. 

Is there a better way to do this in elm-core?


On Sunday, June 5, 2016 at 9:20:24 PM UTC-5, Max Goldstein wrote:
>
> port projects : (Json.Value -> Msg) -> Sub Msg
>
> type Msg = NewProjects Json.Value | OtherThings
>
> subscriptions model =
>   projects NewProjects
>
> Then in the update function, run the decoder on the JSON value in the 
> NewProjects tag, and handle the succeeding and failing cases.
>

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to