Module

Network.RemoteData

Package
purescript-remotedata
Repository
krisajenkins/purescript-remotedata

#RemoteData Source

data RemoteData e a

A datatype representing fetched data.

If you find yourself continually using Maybe (Either e a) to represent data loaded from an external source, or you have a habit of shuffling errors away to where they can be quietly ignored, consider using this. It makes it easier to represent the real state of a remote data fetch and handle it properly.

For more on the motivation, take a look at the blog post How Elm Slays A UI Antipattern. This is a port of that original Elm module.

Constructors

Instances

#toMaybe Source

toMaybe :: forall a e. RemoteData e a -> Maybe a

Convert a RemoteData to a Maybe.

#fromMaybe Source

fromMaybe :: forall a e. Maybe a -> RemoteData e a

Convert a Maybe to RemoteData.

#fromEither Source

fromEither :: forall a e. Either e a -> RemoteData e a

Convert an Either to RemoteData

#maybe Source

maybe :: forall b a e. b -> (a -> b) -> RemoteData e a -> b

Takes a default value, a function, and a RemoteData value. If the data is Success, apply the function to the value, otherwise return the default.

See also withDefault.

#withDefault Source

withDefault :: forall a e. a -> RemoteData e a -> a

If the RemoteData has been successfully loaded, return that, otherwise return a default value.

#_NotAsked Source

_NotAsked :: forall e a. Prism' (RemoteData e a) Unit

#_Loading Source

_Loading :: forall e a. Prism' (RemoteData e a) Unit

#_Failure Source

_Failure :: forall e a. Prism' (RemoteData e a) e

#_Success Source

_Success :: forall e a. Prism' (RemoteData e a) a

#isNotAsked Source

isNotAsked :: forall a e. RemoteData e a -> Boolean

Simple predicate.

#isLoading Source

isLoading :: forall a e. RemoteData e a -> Boolean

Simple predicate.

#isFailure Source

isFailure :: forall a e. RemoteData e a -> Boolean

Simple predicate.

#isSuccess Source

isSuccess :: forall a e. RemoteData e a -> Boolean

Simple predicate.