krisajenkins/elm-exts/25.2.0

NOTE: this package is not compatible with Elm 0.19.1

Exts.RemoteData

A datatype representing fetched data.

If you find yourself continually using Maybe (Result Error a) to represent loaded data, 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.

type RemoteData e a
= NotAsked
| Loading
| Failure e
| Success a

Frequently when you're fetching data from an API, you want to represent four different states: * NotAsked - We haven't asked for the data yet. * Loading - We've asked, but haven't got an answer yet. * Failure - We asked, but something went wrong. Here's the error. * Success - Everything worked, and here's the data.

type alias WebData a =
RemoteData Error a

While RemoteData can model any type of error, the most common one you'll actually encounter is when you fetch data from a REST interface, and get back RemoteData Http.Error a. Because that case is so common, WebData is provided as a useful alias.

map : (a -> b) -> RemoteData e a -> RemoteData e b

Map a function into the Success value.

mapFailure : (e -> f) -> RemoteData e a -> RemoteData f a

Map a function into the Failure value.

mapBoth : (a -> b) -> (e -> f) -> RemoteData e a -> RemoteData f b

Map function into both the Success and Failure value.

withDefault : a -> RemoteData e a -> a

Return the Success value, or the default.

fromResult : Result e a -> RemoteData e a

Convert a Result Error, probably produced from elm-http, to a RemoteData value.

asCmd : Task e a -> Cmd (RemoteData e a)

Convert a web Task, probably produced from elm-http, to a Cmd (RemoteData e a).

append : RemoteData e a -> RemoteData e b -> RemoteData e ( a, b )

Append - join two RemoteData values together as though they were one.

If their value is NotAsked, the result is NotAsked. If their value is Loading, the result is Loading. If both values are Failure, the left one wins.

mappend : RemoteData e a -> RemoteData e b -> RemoteData e ( a, b )

DEPRECATED: Old, incorrect name for append.

isSuccess : RemoteData e a -> Bool

State-checking predicate. Returns true if we've successfully loaded some data.