You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Programming background: >2 years javascript Learning Elm to learn functional programming and its concepts I was confused by the fact that the map function of json decode is order sensitive,
@maxzirps It is not the JSON that must have the fields in order but rather the fact that you are using a Record Constructor:
-- you probably have a Question recordtype alias Question={ address:String, name:String}-- you can create a question with the constructor:Question"Some Address""A Name"-- here the order matters!-- another exampletype alias Person={ name:String, age:Int}Person"Hercules"41-- creates a Person record
The main thing to notice is that in the decoder Question is used as a constructor (... a function). I believe this usage is a bit tricky to notice. If you wold decode the Question to a tuple it would look like so:
type alias Question=(String,String)-- defined as a tupledecoder:DecoderQuestiondecoder =JD.map2 Tuple.pair
(field "address" string)(field "name" string)
Programming background: >2 years javascript
Learning Elm to learn functional programming and its concepts
I was confused by the fact that the map function of json decode is order sensitive,
so if my JSON response looks like this:
and I decode it with:
the values are assigned to the wrong fields.
The text was updated successfully, but these errors were encountered: