On Wed, Nov 16, 2016 at 10:50 PM, Tim Bezhashvyly <[email protected]
> wrote:
> Makes sense but doesn't change much:
>
> (|>) is expecting the right side to be a: Http.Request Shows -> a But the
>> right side is: Http.Request (Maybe Shows) -> Cmd Msg
>
>
Ok, now we're cooking.
You have a Json decoder that produces Shows and it needs to produce Maybe
Shows.
If you use Just instead of identity you should be fine:
decoderColl : Json.Decoder (Maybe Shows)
decoderColl =
Json.map Just
(field "shows" (Json.list decoder))
Just to clarify a little bit more around this. If you throw bad JSON at a
decoder you will get a BadPayload Http.Error as the result of the request.
If you want to capture the failure of the decoder within the decoder you
need something like this:
decoderColl : Json.Decoder (Maybe Shows)
decoderColl =
Json.maybe (field "shows" (Json.list decoder))
This second decoder will not throw a BadPayload because it will be able to
decode every bad JSON to Nothing.
This is useful in some ways but BadPayload errors are more informative.
--
There is NO FATE, we are the creators.
blog: http://damoc.ro/
--
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.