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 e a. RemoteData e a -> Maybe a

Convert a RemoteData to a Maybe.

#fromMaybe Source

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

Convert a Maybe to RemoteData.

#fromEither Source

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

Convert an Either to RemoteData

#maybe Source

maybe :: forall e a b. 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 e a. a -> RemoteData e a -> a

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

#_NotAsked Source

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

#_Loading Source

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

#_Failure Source

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

#_Success Source

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

#isNotAsked Source

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

Simple predicate.

#isLoading Source

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

Simple predicate.

#isFailure Source

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

Simple predicate.

#isSuccess Source

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

Simple predicate.