New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json.Decode should expose "key" as a non-infix name for (:=) #567

Closed
ThomasWeiser opened this Issue Apr 22, 2016 · 3 comments

Comments

Projects
None yet
3 participants
@ThomasWeiser
Contributor

ThomasWeiser commented Apr 22, 2016

NoRedInk/elm-decode-pipeline postulates the abstention of infix operators, IMHO for good reasons, at least in library APIs.

Json.Decode exports the infix operator := without a non-infix name. I propose to give it also a reasonable non-infix name. Can't make up for a good one at the moment, but think about something like at1 key.

Example, using the infix operator:

import Json.Decode as JD exposing ((:=))

decodeName : JD.Decoder String
decodeName = "name" := JD.string

Evading infix operators currently forces to use at with a one-member list:

import Json.Decode as JD

decodeName = JD.at ["name"] JD.string

Proposal (edited):

decodeName = JD.key "name" JD.string
@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Apr 22, 2016

Contributor

How about

decodeName = JD.child "name" JD.string

or something like that? Also possible: field.

Contributor

jvoigtlaender commented Apr 22, 2016

How about

decodeName = JD.child "name" JD.string

or something like that? Also possible: field.

@ThomasWeiser

This comment has been minimized.

Show comment
Hide comment
@ThomasWeiser

ThomasWeiser Apr 22, 2016

Contributor

Musing about the name: Official JSON docs speak of name/value pairs, but name is not a nice name :) Actually, the most used term (beside name) in JSON land seems to be key. This is also the idiom used in Elm's Dict and it already appears as Json.Decode.keyValuePairs.

So I propose: Json.Decode.key as in:

import Json.Decode as JD

decodeName : JD.Decoder String
decodeName = JD.key "name" JD.string
Contributor

ThomasWeiser commented Apr 22, 2016

Musing about the name: Official JSON docs speak of name/value pairs, but name is not a nice name :) Actually, the most used term (beside name) in JSON land seems to be key. This is also the idiom used in Elm's Dict and it already appears as Json.Decode.keyValuePairs.

So I propose: Json.Decode.key as in:

import Json.Decode as JD

decodeName : JD.Decoder String
decodeName = JD.key "name" JD.string

@ThomasWeiser ThomasWeiser changed the title from Json.Decode should expose a non-infix name for (:=) to Json.Decode should expose `key` as a non-infix name for (:=) Apr 22, 2016

@ThomasWeiser ThomasWeiser changed the title from Json.Decode should expose `key` as a non-infix name for (:=) to Json.Decode should expose key as a non-infix name for (:=) Apr 22, 2016

@ThomasWeiser ThomasWeiser changed the title from Json.Decode should expose key as a non-infix name for (:=) to Json.Decode should expose `key` as a non-infix name for (:=) Apr 22, 2016

@ThomasWeiser ThomasWeiser changed the title from Json.Decode should expose `key` as a non-infix name for (:=) to Json.Decode should expose "key" as a non-infix name for (:=) Apr 22, 2016

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz May 19, 2016

Member

I agree that the API should be changed to be more in line with more recent libraries informed by usage, but I do not want to track API suggestions here.

Member

evancz commented May 19, 2016

I agree that the API should be changed to be more in line with more recent libraries informed by usage, but I do not want to track API suggestions here.

@evancz evancz closed this May 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment