canceraiddev / elm-aws-core / AWS.KVDecode

KVDecode provides decoders to interpret lists of (String, String) into some Elm type.

KVDecode is a counter-part to AWS.KVEncode but it has a cut down API. In particular there is no scheme to number items into lists, or to nest field names inside each other - only simple field names and a simple values are supported. The reason for this is that AWS services may return values in header fields, but only do this for relatively simple data models compared with the way in which more complex encodings can be used to pass in arguments.

Key-Value decoders.


type KVDecoder a

The type of Key-Value decoders.

decodeKVPairs : KVDecoder a -> Dict String String -> Result Error a

Parses a list of Key-Value pairs as a strings into the Elm type described by the decoder.

Errors may result if the decoder fails to match the data.

Simple values.

string : KVDecoder String

Decodes a string value.

bool : KVDecoder Basics.Bool

Decodes a Boolvalue from "true" or "false".

int : KVDecoder Basics.Int

Decodes an Int value from a String or fails if the string is not an integer.

float : KVDecoder Basics.Float

Decodes an Float value from a String or fails if the string is not a number.

Succeed or fail.

succeed : a -> KVDecoder a

Succeed with a decoder for a specified value.

fail : String -> KVDecoder a

Make the decoder fail with the specified error message.

Mapping over Key-Value decoders.

map : (a -> value) -> KVDecoder a -> KVDecoder value

Maps over KVDecoder

andThen : (a -> KVDecoder b) -> KVDecoder a -> KVDecoder b

Create decoders that depend on previous results.

Decoding into records.

The term 'object' is used as the convention has been established by miniBill/elm-codec.


type ObjectDecoder a

A decoder of fields of named records.

object : a -> ObjectDecoder a

Creates an object decoder from a record constructor.

field : String -> KVDecoder f -> ObjectDecoder (f -> a) -> ObjectDecoder a

Adds a mandatory field to an ObjectDecoder.

optional : String -> KVDecoder f -> ObjectDecoder (Maybe f -> a) -> ObjectDecoder a

Adds an optional field to an ObjectDecoder.

buildObject : ObjectDecoder a -> KVDecoder a

Turns an ObjectDecoder into a KVDecoder.

Error reporting when decoding fails.


type Error
    = Failure String
    | FailureWithVal String String
    | MissingField String

Describes the possible ways the Key-Value decoding can fail.

errorToString : Error -> String

Converts an Error to String describing the error.