mirror of
https://github.com/typeable/xml-isogen.git
synced 2024-10-03 20:48:19 +03:00
Upd: Nillable cenvenience stuff
This commit is contained in:
parent
b35a07a445
commit
380bdea956
@ -1,3 +1,7 @@
|
||||
nix:
|
||||
packages:
|
||||
- zlib
|
||||
|
||||
resolver: lts-9.21
|
||||
|
||||
packages:
|
||||
|
@ -1 +1,5 @@
|
||||
nix:
|
||||
packages:
|
||||
- zlib
|
||||
|
||||
resolver: lts-11.22
|
||||
|
@ -1,3 +1,7 @@
|
||||
nix:
|
||||
packages:
|
||||
- zlib
|
||||
|
||||
resolver: lts-12.16
|
||||
extra-deps:
|
||||
- dom-parser-3.1.0
|
||||
|
@ -1,23 +1,33 @@
|
||||
{-# LANGUAGE MonoLocalBinds #-}
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
{-# LANGUAGE MonoLocalBinds #-}
|
||||
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
|
||||
|
||||
module Text.XML.Nillable
|
||||
where
|
||||
module Text.XML.Nillable where
|
||||
|
||||
import Control.DeepSeq
|
||||
import Text.XML.DOM.Parser
|
||||
import Text.XML.Writer
|
||||
import Text.XML.ParentAttributes
|
||||
import Control.DeepSeq
|
||||
import Control.Lens
|
||||
import Text.XML.DOM.Parser
|
||||
import Text.XML.ParentAttributes
|
||||
import Text.XML.Writer
|
||||
|
||||
-- | Type that can have explicit null value
|
||||
--
|
||||
-- Null value is indicated by "nil"="true" attribute.
|
||||
newtype Nillable a = Nillable (Maybe a)
|
||||
deriving (Eq, Show, Ord, Read, NFData, ToXML)
|
||||
deriving
|
||||
( Eq, Show, Ord, Read, NFData, ToXML
|
||||
, Functor, Applicative, Monad, Foldable, Traversable)
|
||||
|
||||
_Nillable :: Prism' (Nillable a) a
|
||||
_Nillable = coerced . _Just
|
||||
|
||||
nNill :: Nillable a
|
||||
nNill = Nillable Nothing
|
||||
|
||||
nJust :: a -> Nillable a
|
||||
nJust = Nillable . Just
|
||||
|
||||
instance ToXmlParentAttributes a => ToXmlParentAttributes (Nillable a) where
|
||||
toXmlParentAttributes (Nillable Nothing) =
|
||||
toXmlParentAttributes (Nillable Nothing) =
|
||||
[("{http://www.w3.org/2001/XMLSchema-instance}nil", "true")]
|
||||
toXmlParentAttributes (Nillable (Just a)) = toXmlParentAttributes a
|
||||
|
||||
@ -28,4 +38,4 @@ instance FromDom a => FromDom (Nillable a) where
|
||||
Right
|
||||
case nil of
|
||||
Just "true" -> return (Nillable Nothing)
|
||||
_ -> Nillable . Just <$> fromDom
|
||||
_ -> Nillable . Just <$> fromDom
|
||||
|
@ -1,3 +1,7 @@
|
||||
nix:
|
||||
packages:
|
||||
- zlib
|
||||
|
||||
resolver: lts-10.0
|
||||
extra-deps:
|
||||
- dom-parser-3.0.0
|
||||
|
@ -53,7 +53,9 @@ library
|
||||
|
||||
default-language: Haskell2010
|
||||
default-extensions: CPP
|
||||
, DeriveTraversable
|
||||
, FlexibleInstances
|
||||
, GeneralizedNewtypeDeriving
|
||||
, LambdaCase
|
||||
, TemplateHaskell
|
||||
, TupleSections
|
||||
|
Loading…
Reference in New Issue
Block a user