Skip to content

Instantly share code, notes, and snippets.

@girishso
Created September 25, 2016 13:02
Show Gist options
  • Save girishso/0b116367a77b42d22ac76c4b4cedb2c7 to your computer and use it in GitHub Desktop.
Save girishso/0b116367a77b42d22ac76c4b4cedb2c7 to your computer and use it in GitHub Desktop.
import Html.App exposing (beginnerProgram)
import Html.Events exposing (onClick)
import Date exposing (Date)
import Html exposing (..)
import Json.Decode as Js exposing ((:=))
main =
beginnerProgram { model = 0, view = view, update = update }
view model =
h1 [][text (toString f)]
f =
Js.decodeString userDecoder """{"id":77, "name": "xxx"}"""
type Msg = Increment | Decrement
update msg model =
model
type alias User = {id : Int, name : String}
-- Applicative's `pure`:
constructing : a -> Js.Decoder a
constructing = Js.succeed
-- Applicative's `<*>`:
apply : Js.Decoder (a -> b) -> Js.Decoder a -> Js.Decoder b
apply = Js.object2 (<|)
userDecoder : Js.Decoder User
userDecoder =
constructing User
`apply` ("id" := Js.int)
`apply` ("name" := Js.string)
-- `apply` ("email" := Js.string)
-- `apply` ("created_at" := Js.customDecoder Js.string Date.fromString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment