Skip to content

Instantly share code, notes, and snippets.

@jszmajda
Last active March 8, 2026 06:20
Show Gist options
  • Select an option

  • Save jszmajda/13097b1e5240e43df960090b22be6659 to your computer and use it in GitHub Desktop.

Select an option

Save jszmajda/13097b1e5240e43df960090b22be6659 to your computer and use it in GitHub Desktop.

Revisions

  1. jszmajda revised this gist Sep 3, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sample.elm
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ type alias User =
    -- a better way, right?

    jsonDecoder : JD.Decoder User
    jsonDecoder = JD.map4
    jsonDecoder = JD.map4 User
    (JD.field "id" int)
    (JD.field "email" string)
    (JD.field "firstName" string)
  2. jszmajda created this gist Sep 3, 2017.
    21 changes: 21 additions & 0 deletions sample.elm
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    -- So I'm decoding JSON with this pattern, but there has to be a better way

    import Json.Decode as JD

    type alias User =
    { id : Int
    , email : String
    , firstName : String
    , lastName : String
    }

    -- specifically here: this map4 seems dumb. This function depends on the proper
    -- ordering of the fields to match the record constructor above. There must be
    -- a better way, right?

    jsonDecoder : JD.Decoder User
    jsonDecoder = JD.map4
    (JD.field "id" int)
    (JD.field "email" string)
    (JD.field "firstName" string)
    (JD.field "lastName", string)