diff --git a/book/effects/json.md b/book/effects/json.md index b571e2c9..d9fbda38 100644 --- a/book/effects/json.md +++ b/book/effects/json.md @@ -273,7 +273,7 @@ That is all we needed for our HTTP example, but decoders can do more! For exampl map2 : (a -> b -> value) -> Decoder a -> Decoder b -> Decoder value ``` -This function takes in two decoders. It tries them both and combines their results. So now we can put together two different decoders: +This function takes in a type constructor function and two decoders. It tries both decoders and combines their results using the type constructor. So now we can put together two different decoders: ```elm import Json.Decode exposing (Decoder, map2, field, string, int) @@ -290,6 +290,8 @@ personDecoder = (field "age" int) ``` +Here, since a type alias generates a constructor function for its type, the `Person` constructor is the first argument to map2, followed by the two decoders. + So if we used `personDecoder` on `{ "name": "Tom", "age": 42 }` we would get out an Elm value like `Person "Tom" 42`. If we really wanted to get into the spirit of decoders, we would define `personDecoder` as `map2 Person nameDecoder ageDecoder` using our previous definitions. You always want to be building your decoders up from smaller building blocks!