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

Add Json.Decode.enum #902

Closed
wants to merge 1 commit into
base: dev
from

Conversation

Projects
None yet
3 participants
@BrianHicks

BrianHicks commented Aug 24, 2017

This PR implements Json.Decode.enum, which is enum : Dict String a -> Decoder a.

You use it like this:

funnyBool : Decoder Bool
funnyBool =
  enum <|
    Dict.fromList
      [ ("yes", True)
      , ("no", False)
      ]

Alternatives:

  • use a List (String, a) instead, which makes construction a little easier
  • just do this yourself with andThen. But, context in Slack, it's useful in a lot of places.

Context: https://elmlang.slack.com/archives/C13L7S5GR/p1502488068299237

Ellie with this working: https://ellie-app.com/47dBBznjnHWa1/1

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Aug 24, 2017

Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Aug 24, 2017

Thanks for the pull request! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz May 22, 2018

Member

Can you share a few examples of this with me in one of the slack channels? I think it's a fine time to add it to elm-lang/json, but I want to do a bit more thorough review first.

Member

evancz commented May 22, 2018

Can you share a few examples of this with me in one of the slack channels? I think it's a fine time to add it to elm-lang/json, but I want to do a bit more thorough review first.

@evancz evancz closed this May 22, 2018

@BrianHicks BrianHicks deleted the BrianHicks:json-decode-enum branch May 22, 2018

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