Skip to content

Instantly share code, notes, and snippets.

@tomphp
Created October 25, 2019 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomphp/756948832bdad98652c67d79c8906588 to your computer and use it in GitHub Desktop.
Save tomphp/756948832bdad98652c67d79c8906588 to your computer and use it in GitHub Desktop.
type LoadedContent a
= Loading
| Success a
| Failure
type alias Model
= LoadedContent Logs
-- UPDATE
type Msg
= GotLogs (Result Http.Error Logs)
update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
GotLogs result ->
( handleLoad result, Cmd.none )
-- Easy to undestand way
handleLoad : Result Http.Error a -> LoadedContent a
handleLoad result =
case result of
Ok x ->
Success x
Err _ ->
Failure
-- More functional way
handleLoad : Result Http.Error a -> LoadedContent a
handleLoad = Result.map Success >> Result.withDefault Failure
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment