Created
February 18, 2018 05:01
-
-
Save Chadtech/859af7a374bbe30db8834a6a57d4d36e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Data.Thing | |
exposing | |
( Thing | |
, decoder | |
, encoder | |
) | |
import Json.Encode as Encode exposing (Value) | |
import Json.Decode as Decode exposing (Decoder) | |
type Thing | |
= Thing | |
encode : Thing -> Value | |
encode thing = | |
Encode.string "thing" | |
decoder : Decoder Thing | |
decoder = | |
Decode.string | |
|> Decode.andThen toThingDecoder | |
toThingDecoder : String -> Decoder Thing | |
toThingDecoder str = | |
case str of | |
"Thing" -> | |
Decode.succeed Thing | |
_ -> | |
Decode.fail "Not a thing" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment