Skip to content

Instantly share code, notes, and snippets.

Avatar

Jason Dew jasondew

View GitHub Profile
View action.elm
type Action
= Updated (Result Error Response)
@jasondew
jasondew / JavaAccount.java
Created Jul 9, 2013
Java vs Ruby vs Scala
View JavaAccount.java
public class Account implements Serializable {
private String subdomain;
public String getSubdomain() {
return subdomain;
}
public void setSubdomain(String subdomain) {
this.subdomain = subdomain;
}
View get.elm
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
View update.elm
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
View alternative.elm
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
View http.elm
get : Decoder value -> String -> Task Error value
View basics.elm
type Response
= ...
type Action
= Updated (Maybe Response)
decoder : Decoder Response -- implementation elided
url : String -- ditto
update : Action -> Model -> ( Model, Effects Action )
View keybase.md

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 / http.elm
Created Feb 1, 2016
HTTP error handling
View http.elm
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
View irr.rb
require 'algebra'
class IRR
def self.calculate(profits)
begin
function(profits).zero
rescue Algebra::MaximumIterationsReached => mir
nil
end
You can’t perform that action at this time.