| Copyright | (C) CSIRO 2017-2018 | 
|---|---|
| License | BSD3 | 
| Maintainer | George Wilson <george.wilson@data61.csiro.au> | 
| Stability | experimental | 
| Portability | non-portable | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Data.Sv.Decode.Error
Description
- data DecodeError e- = UnexpectedEndOfRow
- | ExpectedEndOfRow (Vector (SpacedField e))
- | UnknownCategoricalValue e [[e]]
- | BadParse e
- | BadDecode e
 
- newtype DecodeErrors e = DecodeErrors (NonEmpty (DecodeError e))
- decodeError :: DecodeError e -> DecodeValidation e a
- unexpectedEndOfRow :: DecodeValidation e a
- expectedEndOfRow :: Vector (SpacedField e) -> DecodeValidation e a
- unknownCategoricalValue :: e -> [[e]] -> DecodeValidation e a
- badParse :: e -> DecodeValidation e a
- badDecode :: e -> DecodeValidation e a
- validateEither :: Either (DecodeError e) a -> DecodeValidation e a
- validateEither' :: (e -> DecodeError e') -> Either e a -> DecodeValidation e' a
- validateMaybe :: DecodeError e -> Maybe b -> DecodeValidation e b
- validateMaybe' :: (a -> Maybe b) -> DecodeError e -> a -> DecodeValidation e b
- trifectaResultToEither :: Result a -> Either String a
- validateTrifectaResult :: (String -> DecodeError e) -> Result a -> DecodeValidation e a
- bindValidation :: Validation e a -> (a -> Validation e b) -> Validation e b
Documentation
data DecodeError e Source #
DecodeError is a value indicating what went wrong during a parse or
 decode. Its constructor indictates the type of error which occured, and
 there is usually an associated string with more finely-grained details.
Constructors
| UnexpectedEndOfRow | I was looking for another field, but I am at the end of the row | 
| ExpectedEndOfRow (Vector (SpacedField e)) | I should be at the end of the row, but I found extra fields | 
| UnknownCategoricalValue e [[e]] | This decoder was built using the  | 
| BadParse e | The parser failed, meaning decoding proper didn't even begin | 
| BadDecode e | Some other kind of decoding failure occured | 
Instances
| Functor DecodeError Source # | |
| Eq e => Eq (DecodeError e) Source # | |
| Ord e => Ord (DecodeError e) Source # | |
| Show e => Show (DecodeError e) Source # | |
| Generic (DecodeError e) Source # | |
| NFData e => NFData (DecodeError e) Source # | |
| type Rep (DecodeError e) Source # | |
newtype DecodeErrors e Source #
DecodeErrors is a Semigroup full of DecodeError. It is used as the
 error side of a DecodeValidation. When multiple errors occur, they will
 be collected.
Constructors
| DecodeErrors (NonEmpty (DecodeError e)) | 
Instances
| Functor DecodeErrors Source # | |
| Eq e => Eq (DecodeErrors e) Source # | |
| Ord e => Ord (DecodeErrors e) Source # | |
| Show e => Show (DecodeErrors e) Source # | |
| Generic (DecodeErrors e) Source # | |
| Semigroup (DecodeErrors e) Source # | |
| NFData e => NFData (DecodeErrors e) Source # | |
| type Rep (DecodeErrors e) Source # | |
Convenience constructors
decodeError :: DecodeError e -> DecodeValidation e a Source #
Build a failing DecodeValidation
unexpectedEndOfRow :: DecodeValidation e a Source #
Fail with UnexpectedEndOfRow
expectedEndOfRow :: Vector (SpacedField e) -> DecodeValidation e a Source #
Fail with ExpectedEndOfRow. This takes the rest of the row, so that it
 can be displayed to the user.
unknownCategoricalValue :: e -> [[e]] -> DecodeValidation e a Source #
Fail with UnknownCategoricalValue.
 It takes the unknown value and the list of good categorical values.
This mostly exists to be used by the categorical function.
badParse :: e -> DecodeValidation e a Source #
Fail with BadParse with the given message. This is for when the parse
 step fails, and decoding does not even begin.
badDecode :: e -> DecodeValidation e a Source #
Fail with BadDecode with the given message. This is something of a
 generic error for when decoding a field goes wrong.
Conversions
validateEither :: Either (DecodeError e) a -> DecodeValidation e a Source #
Build a DecodeValidation from an Either
validateEither' :: (e -> DecodeError e') -> Either e a -> DecodeValidation e' a Source #
Build a DecodeValidation from an Either, given a function to build the error.
validateMaybe :: DecodeError e -> Maybe b -> DecodeValidation e b Source #
Build a DecodeValidation from a Maybe. You have to supply an error
 to use in the Nothing case
validateMaybe' :: (a -> Maybe b) -> DecodeError e -> a -> DecodeValidation e b Source #
Build a DecodeValidation from a function that returns a Maybe
 You have to supply an error to use in the Nothing case
trifectaResultToEither :: Result a -> Either String a Source #
Helper to convert Text.Trifecta Result to Either.
validateTrifectaResult :: (String -> DecodeError e) -> Result a -> DecodeValidation e a Source #
Convert a Text.Trifecta Result to a DecodeValidation
Re-exports from validation
bindValidation :: Validation e a -> (a -> Validation e b) -> Validation e b #
bindValidation binds through an Validation, which is useful for
 composing Validations sequentially. Note that despite having a bind
 function of the correct type, Validation is not a monad.
 The reason is, this bind does not accumulate errors, so it does not
 agree with the Applicative instance.
There is nothing wrong with using this function, it just does not make a
 valid Monad instance.