Safe Haskell | None |
---|
An API implementing a convenient syntax for defining and manipulating splices. This module was born from the observation that a list of tuples is semantically ambiguous about how duplicate keys should be handled. Additionally, the syntax is inherently rather cumbersome and difficult to work with. This API takes advantage of do notation to provide a very light syntax for defining splices while at the same time eliminating the semantic ambiguity of alists.
Here's how you can define splices:
mySplices :: Splices Text mySplices = do "firstName" ## "John" "lastName" ## "Smith"
- newtype SplicesM s a = SplicesM {}
- type Splices s = SplicesM s ()
- (##) :: Text -> s -> Splices s
- (#!) :: Text -> s -> Splices s
- (#?) :: Text -> s -> Splices s
- noSplices :: Splices s
- runSplices :: SplicesM s a -> Map Text s
- splicesToList :: SplicesM s a -> [(Text, s)]
- add :: Map Text s -> Splices s
- mapS :: (a -> b) -> Splices a -> Splices b
- applyS :: a -> Splices (a -> b) -> Splices b
- insertS :: Text -> s -> Splices s -> Splices s
- insertWithS :: (s -> s -> s) -> Text -> s -> SplicesM s a2 -> SplicesM s ()
- unionWithS :: (s -> s -> s) -> SplicesM s a1 -> SplicesM s a2 -> SplicesM s ()
- ($$) :: Splices (a -> b) -> a -> Splices b
- mapNames :: (Text -> Text) -> Splices a -> Splices a
- prefixSplices :: Text -> Text -> Splices a -> Splices a
- namespaceSplices :: Text -> Splices a -> Splices a
Documentation
A monad providing convenient syntax for defining splices.
type Splices s = SplicesM s ()Source
Convenient type alias that will probably be used most of the time.
(##) :: Text -> s -> Splices sSource
Forces a splice to be added. If the key already exists, its value is overwritten.
(#!) :: Text -> s -> Splices sSource
Tries to add a splice, but if the key already exists, then it throws an error message. This may be useful if name collisions are bad and you want to crash when they occur.
runSplices :: SplicesM s a -> Map Text sSource
Runs the SplicesM monad, generating a map of splices.
splicesToList :: SplicesM s a -> [(Text, s)]Source
Constructs an alist representation.
insertWithS :: (s -> s -> s) -> Text -> s -> SplicesM s a2 -> SplicesM s ()Source
Inserts a splice with a function combining new value and old value.
unionWithS :: (s -> s -> s) -> SplicesM s a1 -> SplicesM s a2 -> SplicesM s ()Source
Union of Splices
with a combining function.
mapNames :: (Text -> Text) -> Splices a -> Splices aSource
Maps a function over all the splice names.
prefixSplices :: Text -> Text -> Splices a -> Splices aSource
Adds a prefix to the tag names for a list of splices. If the existing tag name is empty, then the new tag name is just the prefix. Otherwise the new tag name is the prefix followed by the separator followed by the existing name.
namespaceSplices :: Text -> Splices a -> Splices aSource
prefixSplices
specialized to use a colon as separator in the style of
XML namespaces.