-- | A port of Kris Jenkins' RemoteData Elm module -- . module Network.RemoteData where data RemoteData a b = NotAsked | Loading | Failure a | Success b deriving (Eq, Show) 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