diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-10-30 19:24:00 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@valuemotive.com> | 2021-10-30 19:29:03 +0300 |
| commit | c6d55561bf8422301ea7a2d08b9a7c3e30a1440e (patch) | |
| tree | 33fd6b0c1150b67e2f8ba38806a984c3cecccc75 /src/RemoteData.elm | |
| parent | e24ba80820bd49af72a9e1702ed635e9b63452d1 (diff) | |
Implement authentication
Diffstat (limited to 'src/RemoteData.elm')
| -rw-r--r-- | src/RemoteData.elm | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/RemoteData.elm b/src/RemoteData.elm new file mode 100644 index 0000000..7173851 --- /dev/null +++ b/src/RemoteData.elm @@ -0,0 +1,52 @@ +module RemoteData exposing (..) + +import Http + + +type RemoteData a + = Initial + | Loading + | Failure Http.Error + | Success a + + +withDefault : a -> RemoteData a -> a +withDefault default rd = + case rd of + Success value -> + value + + _ -> + default + + +map : (a -> b) -> RemoteData a -> RemoteData b +map fn rd = + case rd of + Initial -> + Initial + + Loading -> + Loading + + Failure err -> + Failure err + + Success value -> + Success (fn value) + + +andThen : (a -> RemoteData b) -> RemoteData a -> RemoteData b +andThen callback rd = + case rd of + Initial -> + Initial + + Loading -> + Loading + + Failure err -> + Failure err + + Success value -> + callback value |
