You still have this wierd function showPlanetOrError which does Json.Decode stuff and Html stuff.
The problem comes from the shape of your JSON. You are using the name of a field to represent what is actually data. You end up having to instruct the machine on how to handle a "Venus" field and a "Mars" field, etc. It might be human-readable, but it's not very machine readable.
Is it within your power to reshape the JSON sent by your API, so it's just a list of planets, and the planets have a name field?
Yeah, the original JSON is structured poorly. At first I did want to change it the way you describe, but I decided to keep it.
My thinking was that I might have to deal with other poorly structured JSON APIs in the future, but as you say, it has only made things more difficult.
Your second example is really nice to read - it's this kind of code I want to write. I would have gotten there sooner if I hadn't been so stubborn about the JSON shape, so that's a good lesson.
Also, I gotta say your first example is spectacular - the duplication at line 29 and 30 (List.map2 viewUnnamedPlanet) the nesting at line 78 (bodiesDecoder) are pure poetry. :D
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You still have this wierd function
showPlanetOrErrorwhich doesJson.Decodestuff andHtmlstuff.The problem comes from the shape of your JSON. You are using the name of a field to represent what is actually data. You end up having to instruct the machine on how to handle a "Venus" field and a "Mars" field, etc. It might be human-readable, but it's not very machine readable.
Is it within your power to reshape the JSON sent by your API, so it's just a list of planets, and the planets have a
namefield?In this Ellie (ellie-app.com/bYpVTc2KhSta1), there are two different versions of the same thing:
Yeah, the original JSON is structured poorly. At first I did want to change it the way you describe, but I decided to keep it.
My thinking was that I might have to deal with other poorly structured JSON APIs in the future, but as you say, it has only made things more difficult.
Your second example is really nice to read - it's this kind of code I want to write. I would have gotten there sooner if I hadn't been so stubborn about the JSON shape, so that's a good lesson.
Also, I gotta say your first example is spectacular - the duplication at line 29 and 30 (List.map2 viewUnnamedPlanet) the nesting at line 78 (bodiesDecoder) are pure poetry. :D