Skip to content

Instantly share code, notes, and snippets.

View jasondew's full-sized avatar

Jason Dew jasondew

View GitHub Profile
type Action
= Updated Response
| APIError Error
update : Action -> Model -> ( Model, Effects Action )
update action model =
case action of
Updated response -> -- do things
APIError error ->
let
update : Action -> Model -> ( Model, Effects Action )
update action model =
case action of
Updated result ->
case result of
Ok response -> -- do things
Err error -> -- handle error
requestUpdate : Effects Action
requestUpdate =
Http.get decoder url -- Task Error Response
|> Task.toResult -- Task never (Result Error Response)
|> Task.map Updated -- Task never Action
|> Effects.task -- Effects Action
type Action
= Updated (Result Error Response)
type Response
= ...
type Action
= Updated (Maybe Response)
decoder : Decoder Response -- implementation elided
url : String -- ditto
update : Action -> Model -> ( Model, Effects Action )
get : Decoder value -> String -> Task Error value
@jasondew
jasondew / http.elm
Created February 1, 2016 02:35
HTTP error handling
update : Action -> Model -> ( Model, Effects Action )
update action model =
case action of
HandleResponse result ->
case result of
Ok movies ->
( { model | movies = movies }, Effects.none )
Err error ->
let

Keybase proof

I hereby claim:

  • I am jasondew on github.
  • I am jasondew (https://keybase.io/jasondew) on keybase.
  • I have a public key whose fingerprint is D4FD 83C6 D891 37EC 3045 8745 3581 0583 7D91 64D9

To claim this, I am signing this object:

@jasondew
jasondew / JavaAccount.java
Created July 9, 2013 18:58
Java vs Ruby vs Scala
public class Account implements Serializable {
private String subdomain;
public String getSubdomain() {
return subdomain;
}
public void setSubdomain(String subdomain) {
this.subdomain = subdomain;
}
#! /usr/bin/env ruby
# usage:
# $ das_download.rb email password [download_directory]
require "mechanize"
class DasDownloader
attr_reader :agent, :email, :password
def initialize(email, password)