Skip to content

Instantly share code, notes, and snippets.

@Chadtech
Created February 18, 2018 05:01
Show Gist options
  • Save Chadtech/859af7a374bbe30db8834a6a57d4d36e to your computer and use it in GitHub Desktop.
Save Chadtech/859af7a374bbe30db8834a6a57d4d36e to your computer and use it in GitHub Desktop.
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