hedn-0.1.8.2: EDN parsing and encoding

Safe HaskellNone
LanguageHaskell98

Data.EDN.Types.Class

Contents

Synopsis

Type conversion

class ToEDN a where Source #

A type that can be converted to JSON.

Methods

toEDN :: a -> TaggedValue Source #

toEDNv :: a -> Value Source #

Instances

ToEDN Bool Source # 
ToEDN Char Source # 
ToEDN Double Source # 
ToEDN Int Source # 
ToEDN Integer Source # 
ToEDN () Source # 

Methods

toEDN :: () -> TaggedValue Source #

toEDNv :: () -> Value Source #

ToEDN ByteString Source # 
ToEDN ByteString Source # 
ToEDN Text Source # 
ToEDN Text Source # 
ToEDN UTCTime Source # 
ToEDN Value Source # 
ToEDN TaggedValue Source # 
ToEDN [Char] Source # 
ToEDN a => ToEDN [a] Source # 

Methods

toEDN :: [a] -> TaggedValue Source #

toEDNv :: [a] -> Value Source #

ToEDN a => ToEDN (Maybe a) Source # 
(Ord a, ToEDN a) => ToEDN (Set a) Source # 
ToEDN a => ToEDN (Vector a) Source # 
ToEDN a => ToEDN (Tagged a) Source # 
(ToEDN a, ToEDN b) => ToEDN (Either a b) Source # 
(ToEDN a, ToEDN b) => ToEDN (a, b) Source # 

Methods

toEDN :: (a, b) -> TaggedValue Source #

toEDNv :: (a, b) -> Value Source #

(ToEDN a, ToEDN b) => ToEDN (Map a b) Source # 

Methods

toEDN :: Map a b -> TaggedValue Source #

toEDNv :: Map a b -> Value Source #

(ToEDN a, ToEDN b, ToEDN c) => ToEDN (a, b, c) Source # 

Methods

toEDN :: (a, b, c) -> TaggedValue Source #

toEDNv :: (a, b, c) -> Value Source #

(ToEDN a, ToEDN b, ToEDN c, ToEDN d) => ToEDN (a, b, c, d) Source # 

Methods

toEDN :: (a, b, c, d) -> TaggedValue Source #

toEDNv :: (a, b, c, d) -> Value Source #

(ToEDN a, ToEDN b, ToEDN c, ToEDN d, ToEDN e) => ToEDN (a, b, c, d, e) Source # 

Methods

toEDN :: (a, b, c, d, e) -> TaggedValue Source #

toEDNv :: (a, b, c, d, e) -> Value Source #

(ToEDN a, ToEDN b, ToEDN c, ToEDN d, ToEDN e, ToEDN f) => ToEDN (a, b, c, d, e, f) Source # 

Methods

toEDN :: (a, b, c, d, e, f) -> TaggedValue Source #

toEDNv :: (a, b, c, d, e, f) -> Value Source #

(ToEDN a, ToEDN b, ToEDN c, ToEDN d, ToEDN e, ToEDN f, ToEDN g) => ToEDN (a, b, c, d, e, f, g) Source # 

Methods

toEDN :: (a, b, c, d, e, f, g) -> TaggedValue Source #

toEDNv :: (a, b, c, d, e, f, g) -> Value Source #

(ToEDN a, ToEDN b, ToEDN c, ToEDN d, ToEDN e, ToEDN f, ToEDN g, ToEDN h) => ToEDN (a, b, c, d, e, f, g, h) Source # 

Methods

toEDN :: (a, b, c, d, e, f, g, h) -> TaggedValue Source #

toEDNv :: (a, b, c, d, e, f, g, h) -> Value Source #

class FromEDN a where Source #

A type that can be converted from EDN, with a possibility of failure.

When writing an instance, use empty, mzero, or fail to make a conversion fail, e.g. if an Map is missing a required key, or the value is of the wrong type.

Instances

FromEDN Bool Source # 
FromEDN Char Source # 
FromEDN Double Source # 
FromEDN Int Source # 
FromEDN Integer Source # 
FromEDN () Source # 
FromEDN ByteString Source # 
FromEDN ByteString Source # 
FromEDN Text Source # 
FromEDN Text Source # 
FromEDN UTCTime Source # 
FromEDN Value Source # 
FromEDN TaggedValue Source # 
FromEDN [Char] Source # 
FromEDN a => FromEDN [a] Source # 
FromEDN a => FromEDN (Maybe a) Source # 
(Ord a, FromEDN a) => FromEDN (Set a) Source # 
FromEDN a => FromEDN (Vector a) Source # 
FromEDN a => FromEDN (Tagged a) Source # 
(FromEDN a, FromEDN b) => FromEDN (Either a b) Source # 
(FromEDN a, FromEDN b) => FromEDN (a, b) Source # 

Methods

parseEDN :: TaggedValue -> Parser (a, b) Source #

parseEDNv :: Value -> Parser (a, b) Source #

(Ord a, FromEDN a, FromEDN b) => FromEDN (Map a b) Source # 
(FromEDN a, FromEDN b, FromEDN c) => FromEDN (a, b, c) Source # 

Methods

parseEDN :: TaggedValue -> Parser (a, b, c) Source #

parseEDNv :: Value -> Parser (a, b, c) Source #

(FromEDN a, FromEDN b, FromEDN c, FromEDN d) => FromEDN (a, b, c, d) Source # 

Methods

parseEDN :: TaggedValue -> Parser (a, b, c, d) Source #

parseEDNv :: Value -> Parser (a, b, c, d) Source #

(FromEDN a, FromEDN b, FromEDN c, FromEDN d, FromEDN e) => FromEDN (a, b, c, d, e) Source # 

Methods

parseEDN :: TaggedValue -> Parser (a, b, c, d, e) Source #

parseEDNv :: Value -> Parser (a, b, c, d, e) Source #

(FromEDN a, FromEDN b, FromEDN c, FromEDN d, FromEDN e, FromEDN f) => FromEDN (a, b, c, d, e, f) Source # 

Methods

parseEDN :: TaggedValue -> Parser (a, b, c, d, e, f) Source #

parseEDNv :: Value -> Parser (a, b, c, d, e, f) Source #

(FromEDN a, FromEDN b, FromEDN c, FromEDN d, FromEDN e, FromEDN f, FromEDN g) => FromEDN (a, b, c, d, e, f, g) Source # 

Methods

parseEDN :: TaggedValue -> Parser (a, b, c, d, e, f, g) Source #

parseEDNv :: Value -> Parser (a, b, c, d, e, f, g) Source #

(FromEDN a, FromEDN b, FromEDN c, FromEDN d, FromEDN e, FromEDN f, FromEDN g, FromEDN h) => FromEDN (a, b, c, d, e, f, g, h) Source # 

Methods

parseEDN :: TaggedValue -> Parser (a, b, c, d, e, f, g, h) Source #

parseEDNv :: Value -> Parser (a, b, c, d, e, f, g, h) Source #

fromEDN :: FromEDN a => TaggedValue -> Result a Source #

Convert a value from TaggedValue, failing if the types do not match.

fromEDNv :: FromEDN a => Value -> Result a Source #

Convert a value from Value, failing if the types do not match.

EDN value decoding

decode :: FromEDN a => ByteString -> Maybe a Source #

Deserializes a EDN value from a lazy ByteString. If this fails to to incomplete or invalid input, Nothing is returned.

eitherDecode :: FromEDN a => ByteString -> Either String a Source #

Deserializes a EDN value from a lazy ByteString. If this fails to to incomplete or invalid input, Left is returned with an error message.

parse :: (a -> Parser b) -> a -> Result b Source #

Run a Parser.

parseEither :: (a -> Parser b) -> a -> Either String b Source #

Run a Parser with an Either result type.

parseMaybe :: (a -> Parser b) -> a -> Maybe b Source #

Run a Parser with a Maybe result type.

data Parser a Source #

A continuation-based parser type.

Instances

Monad Parser Source # 

Methods

(>>=) :: Parser a -> (a -> Parser b) -> Parser b #

(>>) :: Parser a -> Parser b -> Parser b #

return :: a -> Parser a #

fail :: String -> Parser a #

Functor Parser Source # 

Methods

fmap :: (a -> b) -> Parser a -> Parser b #

(<$) :: a -> Parser b -> Parser a #

Applicative Parser Source # 

Methods

pure :: a -> Parser a #

(<*>) :: Parser (a -> b) -> Parser a -> Parser b #

(*>) :: Parser a -> Parser b -> Parser b #

(<*) :: Parser a -> Parser b -> Parser a #

Alternative Parser Source # 

Methods

empty :: Parser a #

(<|>) :: Parser a -> Parser a -> Parser a #

some :: Parser a -> Parser [a] #

many :: Parser a -> Parser [a] #

MonadPlus Parser Source # 

Methods

mzero :: Parser a #

mplus :: Parser a -> Parser a -> Parser a #

Monoid (Parser a) Source # 

Methods

mempty :: Parser a #

mappend :: Parser a -> Parser a -> Parser a #

mconcat :: [Parser a] -> Parser a #

data Result a Source #

The result of running a Parser.

Constructors

Error String 
Success a 

Instances

Monad Result Source # 

Methods

(>>=) :: Result a -> (a -> Result b) -> Result b #

(>>) :: Result a -> Result b -> Result b #

return :: a -> Result a #

fail :: String -> Result a #

Functor Result Source # 

Methods

fmap :: (a -> b) -> Result a -> Result b #

(<$) :: a -> Result b -> Result a #

Applicative Result Source # 

Methods

pure :: a -> Result a #

(<*>) :: Result (a -> b) -> Result a -> Result b #

(*>) :: Result a -> Result b -> Result b #

(<*) :: Result a -> Result b -> Result a #

Alternative Result Source # 

Methods

empty :: Result a #

(<|>) :: Result a -> Result a -> Result a #

some :: Result a -> Result [a] #

many :: Result a -> Result [a] #

MonadPlus Result Source # 

Methods

mzero :: Result a #

mplus :: Result a -> Result a -> Result a #

Eq a => Eq (Result a) Source # 

Methods

(==) :: Result a -> Result a -> Bool #

(/=) :: Result a -> Result a -> Bool #

Show a => Show (Result a) Source # 

Methods

showsPrec :: Int -> Result a -> ShowS #

show :: Result a -> String #

showList :: [Result a] -> ShowS #

Monoid (Result a) Source # 

Methods

mempty :: Result a #

mappend :: Result a -> Result a -> Result a #

mconcat :: [Result a] -> Result a #

NFData a => NFData (Result a) Source # 

Methods

rnf :: Result a -> () #

Convenience functions

(.=) :: ToEDN a => ByteString -> a -> Pair Source #

Construct a Pair from a key (as EDN keyword) and a value.

(.:) :: (Show k, ToEDN k, FromEDN a) => EDNMap -> k -> Parser a Source #

Retrieve the value associated with the given key of an EDNMap. The result is empty if the key is not present or the value cannot be converted to the desired type.

This accessor is appropriate if the key and value must be present in an object for it to be valid. If the key and value are optional, use '(.:?)' instead.

(.:?) :: (ToEDN k, FromEDN a) => EDNMap -> k -> Parser (Maybe a) Source #

Retrieve the value associated with the given key of an EDNMap. The result is Nothing if the key is not present, or empty if the value cannot be converted to the desired type.

This accessor is most useful if the key and value can be absent from an object without affecting its validity. If the key and value are mandatory, use '(.:)' instead.

(.!=) :: Parser (Maybe a) -> a -> Parser a Source #

Helper for use in combination with .:? to provide default values for optional JSON object fields.

This combinator is most useful if the key and value can be absent from an object without affecting its validity and we know a default value to assign in that case. If the key and value are mandatory, use '(.:)' instead.

Example usage:

 v1 <- o .:? "opt_field_with_dfl" .!= "default_val"
 v2 <- o .:  "mandatory_field"
 v3 <- o .:? "opt_field2"

typeMismatch Source #

Arguments

:: String

The name of the type you are trying to parse.

-> Value

The actual value encountered.

-> Parser a 

Fail parsing due to a type mismatch, with a descriptive message.