Module

Network.RemoteData

#RemoteData

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

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

Convert a RemoteData to a Maybe.

#fromMaybe

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

Convert a Maybe to RemoteData.

#fromEither

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

Convert an Either to RemoteData

#maybe

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

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

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

#_NotAsked

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

#_Loading

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

#_Failure

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

#_Success

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

#isNotAsked

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

Simple predicate.

#isLoading

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

Simple predicate.

#isFailure

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

Simple predicate.

#isSuccess

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

Simple predicate.

Modules