summaryrefslogtreecommitdiff
path: root/Com/Simatime/Network.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bsima.me>2019-11-02 15:33:13 -0700
committerBen Sima <ben@bsima.me>2019-11-02 15:33:13 -0700
commit9d114cfc773171b0a95bd4d2c39f1bb0eb783c8d (patch)
tree20766a760ed0141cf39153565e8552f6739c632d /Com/Simatime/Network.hs
parentd2a37f5de160160eadbacd7b8dc2567f78a0543d (diff)
rename everything back to caps to appease ghc
Diffstat (limited to 'Com/Simatime/Network.hs')
-rw-r--r--Com/Simatime/Network.hs31
1 files changed, 31 insertions, 0 deletions
diff --git a/Com/Simatime/Network.hs b/Com/Simatime/Network.hs
new file mode 100644
index 0000000..e47e891
--- /dev/null
+++ b/Com/Simatime/Network.hs
@@ -0,0 +1,31 @@
+-- | A port of Kris Jenkins' RemoteData Elm module
+-- <https://github.com/krisajenkins/remotedata>.
+--
+module Com.Simatime.Network 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