summaryrefslogtreecommitdiffstats
path: root/src/RemoteData.elm
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2021-10-30 19:24:00 +0300
committerJan Tuomi <jan.tuomi@valuemotive.com>2021-10-30 19:29:03 +0300
commitc6d55561bf8422301ea7a2d08b9a7c3e30a1440e (patch)
tree33fd6b0c1150b67e2f8ba38806a984c3cecccc75 /src/RemoteData.elm
parente24ba80820bd49af72a9e1702ed635e9b63452d1 (diff)
Implement authentication
Diffstat (limited to 'src/RemoteData.elm')
-rw-r--r--src/RemoteData.elm52
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