summaryrefslogtreecommitdiff
path: root/Network
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2020-04-15 09:54:10 -0700
committerBen Sima <ben@bsima.me>2020-04-15 10:06:56 -0700
commitf4b8c0df041b063c0b47d2ec6c818a9c202fd833 (patch)
tree01ad246a83fda29c079847b3397ca6509a7f6106 /Network
parent6ed475ca94209ce92e75f48764cb9d361029ea26 (diff)
Re-namespacing
Moving away from the DNS-driven namespacing toward more condensed names, mostly because I don't like typing so much.
Diffstat (limited to 'Network')
-rw-r--r--Network/RemoteData.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/Network/RemoteData.hs b/Network/RemoteData.hs
new file mode 100644
index 0000000..2fe6557
--- /dev/null
+++ b/Network/RemoteData.hs
@@ -0,0 +1,31 @@
+-- | A port of Kris Jenkins' RemoteData Elm module
+-- <https://github.com/krisajenkins/remotedata>.
+--
+module Network.RemoteData where
+
+data RemoteData a b
+ = NotAsked
+ | Loading
+ | Failure a
+ | Success b
+ deriving (Eq, Show)
+
+-- TODO figure out Http.Error
+-- type WebData a = RemoteData Http.Error a
+
+instance Functor (RemoteData a) where
+ fmap _ NotAsked = NotAsked
+ fmap _ Loading = Loading
+ fmap _ (Failure a) = Failure a
+ fmap f (Success a) = Success (f a)
+
+instance Applicative (RemoteData e) where
+ pure = Success
+ NotAsked <*> _ = NotAsked
+ Loading <*> _ = Loading
+ Failure a <*> _ = Failure a
+ Success a <*> b = fmap a b
+
+fromEither :: Either a b -> RemoteData a b
+fromEither (Left a) = Failure a
+fromEither (Right a) = Success a