jamesrweb/elm-cqrs/4.0.0

NOTE: the latest version is 5.0.3

Cqrs.Query

{ headers : List Header
, timeout : Maybe Float
, tracker : Maybe String
, risky : Bool
}

Configuration for requests resulting in a Cmd

type alias TaskRequestConfig =
{ headers : List Header
, timeout : Maybe Float
, risky : Bool
}

Configuration for requests resulting in a Task

type QueryResponse e a

Represents the possible states of a query.

HTTP

String
-> (e -> f)
-> f
-> (QueryResponse f a -> msg)
-> Decoder a
-> Decoder e
-> Cmd msg

Sends a query to the given URL and returns a Cmd for the given msg containing the parsed Cqrs.Query.QueryResponse e a. The value contained within the Cqrs.Query.QueryResponse e a, will be the value parsed via the provided decoder.

StandardRequestConfig
-> String
-> (e -> f)
-> f
-> (QueryResponse f a -> msg)
-> Decoder a
-> Decoder e
-> Cmd msg

Similar to request but a StandardRequestConfig can be passed in for cases where customisation of the request headers, etc are desired.

String
-> (e -> f)
-> f
-> Decoder a
-> Decoder e
-> Task () (QueryResponse f a)

Sends a query to the given URL and returns a Task which will contain the parsed Cqrs.Query.QueryResponse e a. The value contained within the Cqrs.Query.QueryResponse e a, will be the value parsed via the provided decoder.

TaskRequestConfig
-> String
-> (e -> f)
-> f
-> Decoder a
-> Decoder e
-> Task () (QueryResponse f a)

Similar to requestTask but a TaskRequestConfig can be passed in for cases where customisation of the request headers, etc are desired.

Constructors

Constructs the Data variant of a Cqrs.Query.QueryResponse e a.

This is useful for testing how your UI will respond to the happy path, without actually sending a query.

fail : e -> QueryResponse e a

Constructs the Error variant of a Cqrs.Query.QueryResponse e a.

This is useful for testing how your UI will respond to the sad path, without actually sending a query.

fromResult : Result e a -> QueryResponse e a

Converts a Result e a to a Cqrs.Query.QueryResponse e a

fromRemoteData : (e -> f) -> f -> RemoteData x (QueryResponse e a) -> QueryResponse f a

Converts a given RemoteData x (Cqrs.Query.QueryResponse e a) into a Cqrs.Query.QueryResponse f a.

State

data : QueryResponse e a -> Maybe a

If a given Cqrs.Query.QueryResponse e a was successful, the data it contains will be returned.

data (Data []) --> Just []


data (Error "reason") --> Nothing
reason : QueryResponse e a -> Maybe e

If a given Cqrs.Query.QueryResponse e a was unsuccessful, the reason for the failure will be returned.

reason (Data []) --> Nothing


reason (Error "reason") --> Just "reason"

Mappers

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

Maps the Data variant of a given Cqrs.Query.QueryResponse e a and returns a Cqrs.Query.Response b.

mapError : (e -> f) -> QueryResponse e a -> QueryResponse f a

Maps the Error variant of a given Cqrs.Query.QueryResponse e a.

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

Maps both the Data and the Error variant of a given Cqrs.Query.QueryResponse e a.

unwrap : b -> (a -> b) -> QueryResponse e a -> b

Convert a QueryResponse e a to an a by applying a function if the QueryResponse e a is a Data variant or using the provided default value if it is an Error variant.

unpack : (e -> b) -> (a -> b) -> QueryResponse e a -> b

Convert a QueryResponse e a to an a by applying either the first function if the QueryResponse e a is an Error variant or the second function if the QueryResponse e a is a Data variant.

partition : List (QueryResponse e a) -> ( List a, List e )

Partitions a series of QueryResponse e a instances into a tuple of successful and unsuccessful responses.

merge : QueryResponse a a -> a

When a given Cqrs.Query.QueryResponse e a is actually in the form Cqrs.Query.QueryResponse a a then we can return the underlying value from either state. This is especially useful when the error and value have been mapped to domain types.

filter : e -> (a -> Bool) -> QueryResponse e a -> QueryResponse e a

Filter a given QueryResponse e a if it is in the Data variant and should the predicate not pass, map to a Error variant with the given error. Useful for error value mapping within a given domain.

toResult : QueryResponse e a -> Result e a

Converts a Cqrs.Query.QueryResponse e a to a Result e a

toMaybe : QueryResponse e a -> Maybe a

Converts a Cqrs.Query.QueryResponse e a to a Maybe a

Helpers

withDefault : a -> QueryResponse e a -> a

Provides a default case for a Cqrs.Query.QueryResponse e a in place of the value held within the Error variant.

succeeded : QueryResponse e a -> Bool

Checks if a given Cqrs.Query.QueryResponse e a is a Data variant.

succeeded (Data []) --> True


succeeded (Error "reason") --> False
failed : QueryResponse e a -> Bool

Checks if a given Cqrs.Query.QueryResponse e a is an Error variant.

failed (Data []) --> False


failed (Error "reason") --> True

Codec

decoder : Decoder a -> Decoder e -> Decoder (QueryResponse e a)

Decodes a given payload into a Cqrs.Query.QueryResponse e a.