Why Json.Decode.Pipeline.hardcoded doesn't require a field name?

Viewed 35

Take the example from here: https://tech.chefclub.tv/en/how-to-decode-complex-json-with-elm

type alias Record =
    { uid : String
    , age : Maybe Int
    , version : Float
    }


customDecoder : JD.Decoder Record
customDecoder =
    decode Record
        |> required "uid" JD.string
        |> optional "age" (JD.maybe JD.int) Nothing
        |> hardcoded 1.0

I'm wondering why field names sometimes appear in the decoder, and sometimes don't?

If the field name is good for readability, why the usage here is not

customDecoder =
    decode Record
        |> required "uid" JD.string
        |> optional "age" (JD.maybe JD.int) Nothing
        |> hardcoded "version" 1.0

If the parameter order is enough, then why the usage here is not

customDecoder =
    decode Record
        |> required JD.string
        |> optional (JD.maybe JD.int) Nothing
        |> hardcoded 1.0

I'm wondering if there's an inconsistency API design issue in JSON decoder here ...?

Why Json.Decode.Pipeline.hardcoded doesn't require a field name?

0 Answers
Related