module Propellor.Property.List (
props,
PropertyList(..),
PropertyListType,
PropList(..),
) where
import Propellor.Types
import Propellor.Engine
import Propellor.PropAccum
import Data.Monoid
props :: PropList
props = PropList []
data PropList = PropList [Property HasInfo]
instance PropAccum PropList where
PropList l `addProp` p = PropList (toProp p : l)
PropList l `addPropFront` p = PropList (l ++ [toProp p])
getProperties (PropList l) = reverse l
class PropertyList l where
propertyList :: Desc -> l -> Property (PropertyListType l)
combineProperties :: Desc -> l -> Property (PropertyListType l)
type family PropertyListType t
type instance PropertyListType [Property HasInfo] = HasInfo
type instance PropertyListType [Property NoInfo] = NoInfo
type instance PropertyListType PropList = HasInfo
instance PropertyList [Property NoInfo] where
propertyList desc ps = simpleProperty desc (ensureProperties ps) ps
combineProperties desc ps = simpleProperty desc (combineSatisfy ps NoChange) ps
instance PropertyList [Property HasInfo] where
propertyList desc ps = infoProperty desc (ensureProperties $ map ignoreInfo ps) mempty ps
combineProperties desc ps = infoProperty desc (combineSatisfy ps NoChange) mempty ps
instance PropertyList PropList where
propertyList desc = propertyList desc . getProperties
combineProperties desc = combineProperties desc . getProperties
combineSatisfy :: [Property i] -> Result -> Propellor Result
combineSatisfy [] rs = return rs
combineSatisfy (l:ls) rs = do
r <- ensureProperty $ ignoreInfo l
case r of
FailedChange -> return FailedChange
_ -> combineSatisfy ls (r <> rs)