Safe Haskell | None |
---|---|
Language | Haskell98 |
- class ToEDN a where
- class FromEDN a where
- fromEDN :: FromEDN a => TaggedValue -> Result a
- fromEDNv :: FromEDN a => Value -> Result a
- decode :: FromEDN a => ByteString -> Maybe a
- eitherDecode :: FromEDN a => ByteString -> Either String a
- parse :: (a -> Parser b) -> a -> Result b
- parseEither :: (a -> Parser b) -> a -> Either String b
- parseMaybe :: (a -> Parser b) -> a -> Maybe b
- data Parser a
- data Result a
- (.=) :: ToEDN a => ByteString -> a -> Pair
- (.:) :: (Show k, ToEDN k, FromEDN a) => EDNMap -> k -> Parser a
- (.:?) :: (ToEDN k, FromEDN a) => EDNMap -> k -> Parser (Maybe a)
- (.!=) :: Parser (Maybe a) -> a -> Parser a
- typeMismatch :: String -> Value -> Parser a
Type conversion
A type that can be converted to JSON.
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.
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.
A continuation-based parser type.
The result of running a Parser
.
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"