diff options
Diffstat (limited to 'src/Propellor/PropAccum.hs')
| -rw-r--r-- | src/Propellor/PropAccum.hs | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/src/Propellor/PropAccum.hs b/src/Propellor/PropAccum.hs index dec204a2..61cf3dc8 100644 --- a/src/Propellor/PropAccum.hs +++ b/src/Propellor/PropAccum.hs @@ -2,10 +2,10 @@ module Propellor.PropAccum ( host - , props , PropAccum(..) + , (&) + , (&^) , (!) - , PropList , propigateContainer ) where @@ -25,49 +25,41 @@ import Propellor.PrivData host :: HostName -> Host host hn = Host hn [] mempty --- | Starts accumulating a list of properties. --- --- > propertyList "foo" $ props --- > & someproperty --- > ! oldproperty --- > & otherproperty -props :: PropList -props = PropList [] - -- | Something that can accumulate properties. class PropAccum h where -- | Adds a property. - -- - -- Can add Properties and RevertableProperties - (&) :: IsProp p => h -> p -> h + addProp :: IsProp p => h -> p -> h - -- | Like (&), but adds the property at the front of the list. - (&^) :: IsProp p => h -> p -> h + -- | Like addProp, but adds the property at the front of the list. + addPropFront :: IsProp p => h -> p -> h getProperties :: h -> [Property HasInfo] -instance PropAccum Host where - (Host hn ps is) & p = Host hn (ps ++ [toProp p]) - (is <> getInfoRecursive p) - (Host hn ps is) &^ p = Host hn (toProp p : ps) - (getInfoRecursive p <> is) - getProperties = hostProperties - -data PropList = PropList [Property HasInfo] +-- | Adds a property to a `Host` or other `PropAccum` +-- +-- Can add Properties and RevertableProperties +(&) :: (PropAccum h, IsProp p) => h -> p -> h +(&) = addProp -instance PropAccum PropList where - PropList l & p = PropList (toProp p : l) - PropList l &^ p = PropList (l ++ [toProp p]) - getProperties (PropList l) = reverse l +-- | Adds a property before any other properties. +(&^) :: (PropAccum h, IsProp p) => h -> p -> h +(&^) = addPropFront -- | Adds a property in reverted form. (!) :: PropAccum h => h -> RevertableProperty -> h h ! p = h & revert p -infixl 1 &^ infixl 1 & +infixl 1 &^ infixl 1 ! +instance PropAccum Host where + (Host hn ps is) `addProp` p = Host hn (ps ++ [toProp p]) + (is <> getInfoRecursive p) + (Host hn ps is) `addPropFront` p = Host hn (toProp p : ps) + (getInfoRecursive p <> is) + getProperties = hostProperties + -- | Adjust the provided Property, adding to its -- propertyChidren the properties of the provided container. -- |
