Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. module A exposing (..)
  2.  
  3. import Json.Decode as JD
  4. import Json.Encode as JE
  5.  
  6.  
  7. type alias User =
  8. { id : Int
  9. , theme : Theme
  10. }
  11.  
  12.  
  13. type Theme
  14. = Light
  15. | Dark
  16.  
  17.  
  18. userDecoder =
  19. (JD.map2 User
  20. ( JD.field "id" JD.int )
  21. ( JD.field "theme" decodeTheme )
  22. )
  23.  
  24. -- Can't figure out how to make a custom Json.Decoder.Decoder a
  25. decodeTheme toDecode =
  26. let
  27. valueDe =
  28. JD.decodeString JD.string toDecode
  29. in
  30. case valueDe of
  31. Ok name ->
  32. if (String.toLower name) == "light" then
  33. Light
  34. else
  35. Dark
  36.  
  37. Err msg ->
  38. Dark
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement