Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module A exposing (..)
- import Json.Decode as JD
- import Json.Encode as JE
- type alias User =
- { id : Int
- , theme : Theme
- }
- type Theme
- = Light
- | Dark
- userDecoder =
- (JD.map2 User
- ( JD.field "id" JD.int )
- ( JD.field "theme" decodeTheme )
- )
- -- Can't figure out how to make a custom Json.Decoder.Decoder a
- decodeTheme toDecode =
- let
- valueDe =
- JD.decodeString JD.string toDecode
- in
- case valueDe of
- Ok name ->
- if (String.toLower name) == "light" then
- Light
- else
- Dark
- Err msg ->
- Dark
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement