Safe Haskell | None |
---|---|
Language | Haskell98 |
- decode :: FromEDN a => ByteString -> Maybe a
- encode :: ToEDN a => a -> ByteString
- data Value
- type TaggedValue = Tagged Value
- data Tagged a
- = NoTag !a
- | Tagged !a !ByteString !ByteString
- class ToEDN a where
- class FromEDN a
- toEDN :: ToEDN a => a -> TaggedValue
- fromEDN :: FromEDN a => TaggedValue -> Result a
- fromEDNv :: FromEDN a => Value -> Result a
- (.:) :: (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
- tag :: ByteString -> ByteString -> a -> Tagged a
- notag :: a -> Tagged a
- nil :: TaggedValue
- bool :: Bool -> TaggedValue
- true :: TaggedValue
- false :: TaggedValue
- char :: Char -> TaggedValue
- string :: Text -> TaggedValue
- symbol :: ByteString -> TaggedValue
- symbolNS :: ByteString -> ByteString -> TaggedValue
- keyword :: ByteString -> TaggedValue
- integer :: Integer -> TaggedValue
- floating :: Double -> TaggedValue
- makeList :: [TaggedValue] -> Value
- makeVec :: [TaggedValue] -> Value
- makeSet :: [TaggedValue] -> Value
- makeMap :: [Pair] -> Value
- type Pair = (Value, TaggedValue)
- (.=) :: ToEDN a => ByteString -> a -> Pair
- setTag :: ByteString -> ByteString -> Tagged a -> Tagged a
- getTag :: TaggedValue -> (ByteString, ByteString)
- stripTag :: Tagged a -> a
- parseMaybe :: ByteString -> Maybe TaggedValue
Encoding and 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.
encode :: ToEDN a => a -> ByteString Source #
Serialize a value as a lazy ByteString
.
Core EDN types
A "raw" EDN value represented as a Haskell value.
Nil | |
Boolean !Bool | |
String !Text | |
Character !Char | |
Symbol !ByteString !ByteString | |
Keyword !ByteString | |
Integer !Integer | |
Floating !Double | |
List EDNList | |
Vec !EDNVec | |
Map !EDNMap | |
Set !EDNSet |
Eq Value Source # | |
Ord Value Source # | |
Show Value Source # | |
IsString Value Source # | Strings starting with ":" will become keywords. |
NFData Value Source # | |
FromEDN Value Source # | |
FromEDN TaggedValue Source # | |
ToEDN Value Source # | |
ToEDN TaggedValue Source # | |
IsString (Tagged Value) Source # | Strings will become an tagless EDN strings. |
type TaggedValue = Tagged Value Source #
Abstract namespaced tag.
NoTag !a | |
Tagged !a !ByteString !ByteString |
Functor Tagged Source # | |
FromEDN TaggedValue Source # | |
ToEDN TaggedValue Source # | |
Eq a => Eq (Tagged a) Source # | |
Ord a => Ord (Tagged a) Source # | |
Show a => Show (Tagged a) Source # | |
IsString (Tagged Value) Source # | Strings will become an tagless EDN strings. |
NFData a => NFData (Tagged a) Source # | |
FromEDN a => FromEDN (Tagged a) Source # | |
ToEDN a => ToEDN (Tagged a) Source # | |
Type conversion
A type that can be converted to JSON.
toEDN :: a -> TaggedValue 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.
toEDN :: ToEDN a => a -> TaggedValue 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.
(.:) :: (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"
Constructors
tag :: ByteString -> ByteString -> a -> Tagged a Source #
Attach a namespaced tag to a value.
Basic values
nil :: TaggedValue Source #
Basic EDN nil.
bool :: Bool -> TaggedValue Source #
Basic EDN boolean.
true :: TaggedValue Source #
Const EDN True.
false :: TaggedValue Source #
Const EDN False.
char :: Char -> TaggedValue Source #
Basic EDN character.
string :: Text -> TaggedValue Source #
Basic EDN string.
symbol :: ByteString -> TaggedValue Source #
"Bare" symbol.
symbolNS :: ByteString -> ByteString -> TaggedValue Source #
A namespaced symbol.
keyword :: ByteString -> TaggedValue Source #
Basic EDN keyword.
integer :: Integer -> TaggedValue Source #
Basic EDN integer.
floating :: Double -> TaggedValue Source #
Basic EDN fp number.
Containers
makeList :: [TaggedValue] -> Value Source #
makeVec :: [TaggedValue] -> Value Source #
Create an EDN Vector
from a TaggedValue
list.
makeSet :: [TaggedValue] -> Value Source #
Create an EDN Set
from a TaggedValue
list.
makeMap :: [Pair] -> Value Source #
Create an EDN Map
from a assoc list with untagged keys and tagged values.
type Pair = (Value, TaggedValue) Source #
A key/value pair for a EDN Map
(.=) :: ToEDN a => ByteString -> a -> Pair Source #
Construct a Pair
from a key (as EDN keyword) and a value.
Tag manipulation
setTag :: ByteString -> ByteString -> Tagged a -> Tagged a Source #
Replace a tag on a Tagged
value.
getTag :: TaggedValue -> (ByteString, ByteString) Source #
Extract namespace and tag from a tagged container. Will be a pair of empty
for tagless containers.
Parsing
parseMaybe :: ByteString -> Maybe TaggedValue Source #
Parse a lazy ByteString
into a TaggedValue
.
If fails due to incomplete or invalid input, Nothing
is returned.