@@ -1,23 +1,33 @@
1+{-# LANGUAGE MonoLocalBinds #-}
12{-# LANGUAGE OverloadedStrings #-}
2−{-# LANGUAGE MonoLocalBinds #-}
3−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
43
5−module Text.XML.Nillable
6−where
4+module Text.XML.Nillable where
75
8−import Control.DeepSeq
9−import Text.XML.DOM.Parser
10−import Text.XML.Writer
11−import Text.XML.ParentAttributes
6+import Control.DeepSeq
7+import Control.Lens
8+import Text.XML.DOM.Parser
9+import Text.XML.ParentAttributes
10+import Text.XML.Writer
1211
1312-- | Type that can have explicit null value
1413--
1514-- Null value is indicated by "nil"="true" attribute.
1615newtype Nillable a = Nillable (Maybe a)
17− deriving (Eq, Show, Ord, Read, NFData, ToXML)
16+ deriving
17+ ( Eq, Show, Ord, Read, NFData, ToXML
18+ , Functor, Applicative, Monad, Foldable, Traversable)
19+
20+_Nillable :: Prism' (Nillable a) a
21+_Nillable = coerced . _Just
22+
23+nNill :: Nillable a
24+nNill = Nillable Nothing
25+
26+nJust :: a -> Nillable a
27+nJust = Nillable . Just
1828
1929instance ToXmlParentAttributes a => ToXmlParentAttributes (Nillable a) where
20− toXmlParentAttributes (Nillable Nothing) =
30+ toXmlParentAttributes (Nillable Nothing) =
2131 [("{http://www.w3.org/2001/XMLSchema-instance}nil", "true")]
2232 toXmlParentAttributes (Nillable (Just a)) = toXmlParentAttributes a
2333
@@ -28,4 +38,4 @@ instance FromDom a => FromDom (Nillable a) where
2838 Right
2939 case nil of
3040 Just "true" -> return (Nillable Nothing)
31− _ -> Nillable . Just <$> fromDom
41+ _ -> Nillable . Just <$> fromDom