Created
October 25, 2019 11:18
-
-
Save tomphp/756948832bdad98652c67d79c8906588 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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